Skip to content

Annotations

Eugen Neufeld edited this page Aug 13, 2021 · 4 revisions

Model elements can be annotated with various annotations similar to the one found in the Jackson library. These annotations will be use by the mapper to modify the output of the serializer.

JsonProperty

This annotation can be used on any kind of features to modify the field name.

package org.emfjson.sample

annotation "JsonProperty" as JsonProperty

class User {
	@JsonProperty( value = "user_name" )
	String name
}

The output

{
  "eClass": "http://emfjson.org/domain#//User",  
  "user_name": "Bob"
}

This annotation can also be used on operations. In that case the annotation indicates the mapper that the resulting value of the operation execution should be serialize.

Note that this annotation will work only on parameter less operations.

package org.emfjson.sample

annotation "JsonProperty" as JsonProperty

class User {
	@JsonProperty( value = "user_name" )
	String name

  @JsonProperty
  op String hello() {
    "hello World"
  }
}

This will result in this output

{
  "eClass": "http://emfjson.org/domain#//User",  
  "user_name": "Bob",
  "hello": "Hello World"
}
Clone this wiki locally