java - How do I get @JsonIgnore to work so that JSON are not returned recursively? -


i have following java class.

@component @jsonignoreproperties({"begin", "end"}) public class event extends resourcesupport {      @jsonproperty("name")     private final string name;      @jsonproperty("description")     private final string description;      @jsonproperty("timezone")     private final zoneid timezone;     private final localdatetime begin;     private final localdatetime end; 

this gets returned in rest service. regardless of returns deep object representation of localdatetime, below.

    ... {"hour":1,"minute":0,"second":0,"nano":0},"midnightendofday":false},{"month":"october","timedefinition":"utc","standardoffset":{"totalseconds":3600,"id":"+01:00","rules":{"fixedoffset":true,"transitions":[],"transitionrules":[]}},"offsetbefore":{"totalseconds":7200,"id":"+02:00","rules":{"fixedoffset":true,"transitions":[],"transitionrules":[]}},"offsetafter":{"totalseconds":3600,"id":"+01:00     ... 

i have tried put @jsonignore directly on them.

below controller:

@requestmapping("/api/hello")     @responsebody     httpentity<event> getevent() {         event event = new event("name", "description", zoneid.of("europe/paris"),                  localdatetime.now().plusdays(1), localdatetime.now().plusdays(2));          event.add(linkto(methodon(eventapi.class).getevent()).withselfrel());           return new responseentity<event>(event, httpstatus.ok);      } 

i trying out spring hateoas, i'm not sure if has it.

is there different development pattern should using, because of opinionated nature of springboot?

for jsonignoreproperties work serialization must specify variable name(s) ignore e.g.

@jsonignoreproperties({"begin", "end", "timezone"}) 

according documentation these logical names e.g. there getters named getbegin() , getend()

you can field ignored during serialization annotating field declaration or getter. e.g.1

@jsonignore private final localdatetime begin; 

e.g.2

@jsonignore public localdatetime getbegin() {     return begin; } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -