emfjson / emfjson-jackson

JSON Binding for Eclipse Modeling Framework
https://emfjson.github.io
Other
80 stars 23 forks source link

Allow Jackson support for YAML and others #102

Closed maho7791 closed 6 years ago

maho7791 commented 6 years ago

Providing an additional static method 'setupDefaultMapper' with a parameter of type com.fasterxml.jackson.core.JsonFactory would allow to put e.g. a YamlFactory as constructor parameter for the ObjectMapper instance.

So there would be the possibilty to extend EMFJson to serialize/deserialize YAML without further changes.

We already tested it for serializing YAML which worked.

public static ObjectMapper setupDefaultMapper() {
        return setupDefaultMapper(null);
}

public static ObjectMapper setupDefaultMapper(JsonFactory factory) {
        final ObjectMapper mapper = factory == null ? new ObjectMapper() : new ObjectMapper(factory);
        // same as emf
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
        dateFormat.setTimeZone(TimeZone.getDefault());

        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        mapper.setDateFormat(dateFormat);
        mapper.setTimeZone(TimeZone.getDefault());
        mapper.registerModule(new EMFModule());

        return mapper;
}

You can that say: ObjectMapper mapper = EMFModule.setupDefaultMapper(new YamlFactory());

https://github.com/FasterXML/jackson-dataformats-text/tree/master/yaml

ghillairet commented 6 years ago

Done in https://github.com/emfjson/emfjson-jackson/commit/a57375b28224fc236ec8ffe358a852cfb102e9e3