eclipse-emfcloud / emfjson-jackson

emfjson-jackson
Other
16 stars 15 forks source link

Raw (de)serialization using `@JsonRawValue` #46

Closed janhicken closed 2 years ago

janhicken commented 2 years ago

Jackson features an annotation named @JsonRawValue:

@JsonRawValue: per-property marker that can be used to specify that the value of property is to be included in serialization ''exactly'' as is, with no escaping or decoration -- useful for embedding pre-serialized JSON (or whatever data format is being used) in output

It would be handy to also have this in emfjson, both for serialization as well as deserialization, where the latter is currently not supported by Jackson's annotation.

An example Xcore:

class Foo {
  @JsonRawValue(value="true")
  String raw
}

The following JSON object and EObject should be equivalent:

{
  "eClass": "http://foo/model#//Foo",
  "raw": {
    "foo": "bar"
  }
}
var foo = ModelFactory.eINSTANCE.createFoo();
foo.setRaw("{\"foo\":\"bar\"}")