Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue when implementing collection on grid object using Jackson in Spring

 
Sarin Thanissery
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we are using spring jackson conversion for populating the jq grid(josn created using Jackson), we are using an dto object to populate the grid. But when the dto object implements collection, we are experiencing a strange behaviour. Only the list are returned and it ignores other properties like count, pageSize etc. Please have a look at the dto class,

the TestDto class is,
public class TestDto<T> implements Serializable, Collection<T> {

protected int count;
protected int pageSize;
protected Collection<T> rows;
public TestDto(int count, int pageSize, Collection<T> rows) {
this.rows= rows;
this.count = count;
this.pageSize = pageSize;
}

public int getPageSize() {
return pageSize;
}

public int getCount() {
return count;
}

public Collection<T> getRows() {
return rows;
}

/** overrided methods **/
}


In the client side, I am getting only the list of datas. Other properties(count, pagesize) are ignored, when I removed the implements collection part, all properties are available on client side. But we need to implement the collection part

Could you please help me to fix the issue, is there any way to fix the issue using jacksonannotation

Regards ST
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try putting @JsonProperty on those two fields or getters and see if that forces the inclusion.

Just a question but why does it have to implement Collection?

Mark
 
Sarin Thanissery
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

I have tried @JsonProperty option, but it didnt work, I got a clue why it is happening

I have an overrided method on implementing collection,

public Iterator<T> iterator() {
return rows.iterator();
}

This is causing problem, don't know Jackson has any dependency on method, any thoughts from your side?

Note: this class is used for pagination purpose, so I need to implement collection<t>

Thanks

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarin Thanissery wrote:Hi Mark,

I have tried @JsonProperty option, but it didnt work, I got a clue why it is happening

I have an overrided method on implementing collection,

public Iterator<T> iterator() {
return rows.iterator();
}

This is causing problem, don't know Jackson has any dependency on method, any thoughts from your side?

Note: this class is used for pagination purpose, so I need to implement collection<t>

Thanks



Sorry, but most Page type objects that I have seen/used don't implement Collection. It can hold a reference to a Collection, but not really a reason why it would need to implement Collection itself.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic