Comments (19)
The properties are mapped correctly. The only thing Jakcson does not see is your JsonTypeInfo annotation. You can create a wrapper like this :
public class ListWrapper extends List<MyEntityWithJsonTypeInfo> {
public ListWrapper(List<? extends MyEntityWithJsonTypeInfo> list) {
super(list); // may need a cast
}
}
Or a little more generic :
public class Wrapper<T> {
private final List<T> values;
public Wrapper(List<T> values) {
this.values=values;
}
@JsonTypeInfo(....)
public List<T> getValues() {
return values;
}
}
Jackson will still see Wrapper and List but you annotated the property values with the JsonTypeInfo so it should see it.
And other way is to add JsonTypeInfo to Object via mix in annotation. This way, Jackson will add the type info to any class.
from gwt-jackson.
I can't implement the solution. It's a problem on server-side.
gwt-jackson does not have this problem because the type is available in generators.
You have to find a workaround on server-side with your REST implementation and jackson.
As the author says in the comment, the problem seems to appear only if you use generics on root type. Use a wrapper and you should be ok.
from gwt-jackson.
Yeah I am doing that, but I now have about 35 wrapper classes :S Well I'll look into how I can do this. Thanks!
from gwt-jackson.
Maybe you can reduce to one wrapper by using your super class with the JsonTypeInfo.
from gwt-jackson.
How could I do this? (If you don't mind explaining to me haha)
from gwt-jackson.
Thanks for the reply, I tried the generic wrapper and it doesn't seem to work still
public class JacksonList<T> {
private final List<T> elements;
public JacksonList(List<T> elements) {
this.elements=elements;
}
@JsonTypeInfo( use = JsonTypeInfo.Id.CLASS )
public List<T> get() {
return elements;
}
}
Causes: com.github.nmorel.gwtjackson.client.exception.JsonDeserializationException: Cannot find the property @class containing the type information
from gwt-jackson.
That's strange. Do you have the generated json ?
I'll try to do a few test when I find some time.
from gwt-jackson.
[
{
"@id":1,
"id":1,
"owner":null,
"description":"fghgfhfhf fhfghfghfghfghfgh fhfhf",
"causesSummary":null,
"consequencesSummary":null,
"actionsSummary":null,
"lessonsSummary":null,
"conclusion":"ytryuytuuuuuuuuuuu",
"creationDate":"2014-09-18T06:00:17.167+0000",
"date":"2014-09-18T06:00:00.000+0000",
"quantity":null,
"secondaryQuantity":null,
"product":null,
"nptg":false,
"transportRelated":false,
"commitOpening":false,
"commitInvestigation":true,
"commitReview":false,
"processState":{
"@class":"nz.co.doltech.ims.shared.domains.Process",
"@id":2,
"id":3,
"name":"Review",
"description":"Review and Feedback Process",
"nametoken":"review",
"order":3,
"removed":false
}
}
from gwt-jackson.
how can it return an array when you are giving an object ?
You should have a json object with one property that is an array.
from gwt-jackson.
Not sure I completely understand what you are meaning
return new JacksonList<Incident>(incidentService.getIncidents(filter, fetchCollections)).get();
That is the call I am making, getIncidents returns a List object.
from gwt-jackson.
Oh, don't call get(). Return the JacksonList directly and rename the get() method to getValues() or anything else.
from gwt-jackson.
Oh, so I don't need to call get? Instead I need to add JacksonList as the return type? I understand now :)
from gwt-jackson.
Yes, if you don't, it's like before, you return a simple list.
from gwt-jackson.
Right of course, awesome man! That makes sense haha.
from gwt-jackson.
So I did this:
public class JacksonList<T> {
private final ArrayList<T> elements;
public JacksonList(ArrayList<T> elements) {
this.elements = elements;
}
@JsonTypeInfo( use = JsonTypeInfo.Id.CLASS )
public ArrayList<T> getElements() {
return elements;
}
}
getting this result and its still not working:
{
"elements":[
{
"@id":1,
"id":1,
"owner":null,
"description":"fghgfhfhf fhfghfghfghfghfgh fhfhf",
"causesSummary":null,
"consequencesSummary":null,
"actionsSummary":null,
"lessonsSummary":null,
"conclusion":"ytryuytuuuuuuuuuuu",
"creationDate":"2014-09-18T06:00:17.167+0000",
"date":"2014-09-18T06:00:00.000+0000",
"quantity":null,
"secondaryQuantity":null,
"product":null,
"nptg":false,
"transportRelated":false,
"commitOpening":false,
"commitInvestigation":true,
"commitReview":false,
"processState":{
"@class":"nz.co.doltech.ims.shared.domains.Process",
"@id":2,
"id":3,
"name":"Review",
"description":"Review and Feedback Process",
"nametoken":"review",
"order":3,
"removed":false,
"incidentJoinProcesses":[
],
"sections":[
]
}
}
So sorry I'm spamming this bro, you've been such a great help. Thanks for that.
from gwt-jackson.
Well, I don't know. I just did the test and it worked for me :
public static class Wrapper<T> {
private final List<T> values;
public Wrapper( List<T> values ) {this.values = values;}
@JsonTypeInfo( use = Id.CLASS )
public List<T> getValues() {
return values;
}
}
public static class Toto {
public String name = "Toto";
}
@Test
public void testTypeInfo() throws IOException {
Wrapper<?> wrapper = new Wrapper<Toto>( Arrays.asList( new Toto() ) );
objectMapper.writeValue( System.out, wrapper );
}
The test prints :
{"values":[{"@class":"com.github.nmorel.gwtjackson.jackson.options.WriteNullMapValuesOptionJacksonTest$Toto","name":"Toto"}]}
from gwt-jackson.
Ah well its not exactly the same as mine, I am using objects which super class is this:
@JsonTypeInfo( use = JsonTypeInfo.Id.CLASS )
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public abstract class DomainObject implements Serializable, IsSerializable {
public abstract int getId();
public abstract void setId(int id);
}
That is the only difference I can think of here. Try add a super class with those values.
from gwt-jackson.
Are you able to test this with the super class?
from gwt-jackson.
Still works for me with the super class
public static class Wrapper<T> {
private final List<T> values;
public Wrapper( List<T> values ) {this.values = values;}
@JsonTypeInfo( use = Id.CLASS )
public List<T> getValues() {
return values;
}
}
@JsonTypeInfo( use = JsonTypeInfo.Id.CLASS )
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)
public static abstract class DomainObject implements Serializable, IsSerializable {
public abstract int getId();
public abstract void setId(int id);
}
public static class Toto extends DomainObject {
public String name = "Toto";
@Override
public int getId() {
return 10;
}
@Override
public void setId( int id ) {
}
}
@Test
public void testTypeInfo() throws IOException {
Wrapper<?> wrapper = new Wrapper<Toto>( Arrays.asList( new Toto() ) );
objectMapper.writeValue( System.out, wrapper );
}
The output :
{
"values" : [ {
"@class" : "com.github.nmorel.gwtjackson.jackson.options.WriteNullMapValuesOptionJacksonTest$Toto",
"@id" : 1,
"name" : "Toto",
"id" : 10
} ]
}
from gwt-jackson.
Related Issues (20)
- HashMap <SimplePojo, Set <Integer>> ...does not serialize into Json HOT 2
- No source code is available for type com.fasterxml.jackson.databind.ObjectMapper; did you forget to inherit a required module? HOT 3
- Support for java.util.Optional HOT 1
- Expected a string but was BEGIN_OBJECT at line 1 column 2 HOT 1
- Please REVERT the dependency on Jackson 2.9.*, Jackson 2.9.* is NOT compatible with GWT. HOT 2
- Support for @JsonCreator(mode = Mode.DELEGATING)
- Custom deserializer compilation error
- Getter returning Optional<T> of nullable T causing compilation error HOT 2
- GWT 2.6.1 + GwtJackson 0.15.3 HOT 3
- JsonSerializationContext.Builder override not working as expected
- Error:GWT Compiler: No source code is available for type com.fasterxml.jackson.annotation.JsonTypeInfo.As; did you forget to inherit a required module?
- JsonTypeInfo defaultImpl attribute not working HOT 1
- Update jackson dependency to 2.9.8
- Update javapoet dependency to 1.11.1
- Support for JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE
- Annotations on Java8 default interface are ignored HOT 1
- Can't figure out the stackoverflow I am getting
- More (de)serialization customization (JsonFilter or equivalent)
- Double.NaN / NEGATIVE_INFINITY / POSITIVE_INFINITY - Numeric values must be finite, but was
- Many compile problems
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gwt-jackson.