I have a class that we use for paged results such as:
< Code> Public Square PaginatedList & LT; T & gt; Linkedist extension & lt; T & gt; {Private Ent Offset; Private count; Private Ent Total ResultCount; // ...}
And I think that Jackson wants to do this in such a way:
{"result": [1, 2,3], "offset": 0, "count": 3, "total rationalcount": 15}
( where three integer values in the original list are 1,2 and 3 ) )
In my first attempt I came to know that Jackson ignores any property on any property on classes which is assigned to the collection class. In the end, it makes sense, and so I am looking for an alternate solution now. A search of o as a result of two similar questions:
However, both of these suggestions to switch as a result Heritage for creation
I am specifically looking for a solution that allows the class to expand the archive This 'paged list' is part of the common core of enterprise class, And extends the archive so that it can be used as a collection (and self-sufficient) throughout the code. It is being said that the change in structure is not an option, I am free to comment and otherwise I change this class as described above for the support of the serialization.
Therefore, what I can tell, there are two parts that I am getting (which I am seeing in an answer):
- Jackson has the additional assets To see how to go?
- How can JSON go to label the contents of the collection as a 'result' property in JSON output?
( PS: I'm only concerned with serialization. )
I solved this by making a JasonSyrailizer example: << p>
/ P> And, of course, register it as a module: Public class paged list surgerizer enhances JsonSerializer & lt; Paged list & gt; {@ Override Public Class & lt; Paged list & gt; Handle Type () {Paged List. Return to Class; } @ Override Public Waste Serialization (Paginated Cost, Jason Zennerrator Jaegen, SerialIser Provider Provider) IOException throws, Jason's processing exception {jgen.writeStartObject (); Jgen.writeArrayFieldStart ("Results"); (Item entry: value) {jgen.writeObject (entry); } Jgen.writeEndArray (); Jgen.writeNumberField ("offset", value.offset); Jgen.writeNumberField ("count", value.count); Jgen.writeNumberField ("Total Result Count", Value TotalsResultCount); Jgen.writeEndObject (); }}
simple module test module = new simple module ("Paged ListsSerializer module ", New Version (1, 0), 0, Blank, Null, Zero)); TestModule.addSerializer (new paged ListsSerializer ()); Mapper.registerModule (testModule);
No comments:
Post a Comment