package org.openecomp.core.utilities.yaml;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.core.utilities.CommonMethods;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import java.util.Map;
import java.util.Set;
+
/**
* The type Yaml util.
*/
public class YamlUtil {
- private static Logger logger = LoggerFactory.getLogger(YamlUtil.class);
+ private static Logger logger = (Logger) LoggerFactory.getLogger(YamlUtil.class);
/**
* Yaml to object t.
*
* @param <T> the type parameter
* @param yamlContent the yaml content
- * @param typClass the typ class
+ * @param typClass the t class
* @return the t
*/
public <T> T yamlToObject(String yamlContent, Class<T> typClass) {
*
* @param <T> the type parameter
* @param yamlContent the yaml content
- * @param typClass the typ class
+ * @param typClass the t class
* @return the t
*/
public <T> T yamlToObject(InputStream yamlContent, Class<T> typClass) {
yamlContent.close();
}
} catch (IOException ignore) {
- //nothing to dd
+ //do nothing
}
}
}
/**
* Gets constructor.
*
- * @param <T> the type parameter
- * @param typClass the typ class
+ * @param <T> the type parameter
+ * @param typClass the t class
* @return the constructor
*/
public <T> Constructor getConstructor(Class<T> typClass) {
return new MyPropertyUtils();
}
+
/**
* Yaml to map map.
*
* Object to yaml string.
*
* @param <T> the type parameter
- * @param obj the obj
+ * @param obj the obj
* @return the string
*/
public <T> String objectToYaml(Object obj) {
private class CustomRepresenter extends Representer {
+ @Override
+ protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
+ //remove the bean type from the output yaml (!! ...)
+ if (!classTags.containsKey(javaBean.getClass())) {
+ addClassTag(javaBean.getClass(), Tag.MAP);
+ }
+
+ return super.representJavaBean(properties, javaBean);
+ }
+
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
Object propertyValue, Tag customTag) {
: defaultNode;
}
}
-
- @Override
- protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
- //remove the bean type from the output yaml (!! ...)
- if (!classTags.containsKey(javaBean.getClass())) {
- addClassTag(javaBean.getClass(), Tag.MAP);
- }
-
- return super.representJavaBean(properties, javaBean);
- }
}
* The type My property utils.
*/
public class MyPropertyUtils extends PropertyUtils {
+ //Unsorted properties
+ @Override
+ protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess)
+ throws IntrospectionException {
+ return new LinkedHashSet<Property>(getPropertiesMap(type,
+ BeanAccess.FIELD).values());
+ }
+
@Override
public Property getProperty(Class<?> type, String name) throws IntrospectionException {
if (name.equals("default")) {
return super.getProperty(type, name);
}
- //Unsorted properties
- @Override
- protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess beanAccess)
- throws IntrospectionException {
- return new LinkedHashSet<Property>(getPropertiesMap(type,
- BeanAccess.FIELD).values());
- }
-
}
/**
super(theRoot);
}
- @Override
- protected Map<Object, Object> constructMapping(MappingNode node) {
- try {
- return super.constructMapping(node);
- } catch (IllegalStateException exception) {
- throw new ParserException("while parsing MappingNode", node.getStartMark(),
- exception.getMessage(), node.getEndMark());
- }
- }
-
@Override
protected Map<Object, Object> createDefaultMap() {
final Map<Object, Object> delegate = super.createDefaultMap();
}
};
}
+
+ @Override
+ protected Map<Object, Object> constructMapping(MappingNode node) {
+ try {
+ return super.constructMapping(node);
+ } catch (IllegalStateException exception) {
+ throw new ParserException("while parsing MappingNode",
+ node.getStartMark(), exception.getMessage(),
+ node.getEndMark());
+ }
+ }
}
}