0

I have the following POJO (within constructors etc..):

public  class GlobalData  implements Serializable {

//constructors getters and setters

    @org.codehaus.jackson.annotate.JsonProperty("size-guide")   
    private List<SizeGuide> sizeGuides;

}

With the attribute sizeGuide marked with JsonProperty , so when I marshall this using ObjectMapper , the attribute will appear in the JSON named size-guide instead of sizeGuide.

HOWEVER , this is not working , when I do the ObjectMapper.write value as String method , the attribute doesn't "change" his name , it still appear as sizeGuide.

Any hint?

Nexussim Lements
  • 535
  • 1
  • 15
  • 47

2 Answers2

1

You need to use

public  class GlobalData  implements Serializable {

//constructors getters and setters

    @com.fasterxml.jackson.annotation.JsonProperty("size-guide")   
    private List<SizeGuide> sizeGuides;

}
Smile
  • 3,832
  • 3
  • 25
  • 39
1

You might also want to annotate the getter for getSizeGuides as per above - for me variable annotation sometimes doesn't work as getter seem to get precedence when (un)marshalling JSON. Some explanation and examples are here: http://www.javabyexamples.com/how-to-change-property-name-with-jackson/

Nestor Milyaev
  • 5,845
  • 2
  • 35
  • 51