-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CollectionSerializer only processes first entry #255
Comments
I have the same problem, have you solved it? |
What is the JSON input for this part: |
I can only talk about my case, that is a little bit different from the one that @cpoels reported.
in which History is a simple class, without generics or anything else. I have extended the Jersey's AbstractMessageReaderWriterProvider
in which the genericType is History[].class, I have checked it.
|
I just want to add that without a custom deserializer, I have no problems with arrays. |
@notarmara In your custom deserializer you are handling jsonp yourself, so it looks to be either: a bug on jsonp, or an incorrect json parsing. Without a sample JSON text (the input for JsonParser) it is hard to tell. Looking at As a side note, you are creating Jsonb inside |
yes can be a bug of jsonp, I'm trying to understand where is the problem for this reason I involved you. |
It would be best to narrow down the problem to Yasson outside of Jersey context. Do you have a HTTP request log? Can you save the JSON feeded from parser and log it? |
yes let's will try to go down in deep. this is the operations' sequence performed: Now my custom deserializer is loaded: this is the result of parser.getObject(): I have also tryied to perform parser.getArray() but received an error becouse the START_OBJECT event was called. After that the parser.hasNext() is called but the call returns and an array of one element is created by the I hope I'm clear now. please tell me if you need more information. |
I don't see any problem in provided screens, you have an JSON with an json array as root and one json object inside this array. You get it deserialized once as expected. What is missing? Am I correct to say it would be the same as calling: In your case If you want a deserializer for whole array instead of its member type you would define it as:
|
Just tried following code on master branch and it works as expected: @Test
public void testDeserializeArray() {
String json = "[{\"stringProperty\":\"Property 1 value\"},{\"stringProperty\":\"Property 2 value\"}]";
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withDeserializers(new
SimplePojoDeserializer()));
SimplePojo[] result = jsonb.fromJson(json, SimplePojo[].class);
Assert.assertEquals(2, result.length);
}
public class SimplePojoDeserializer implements JsonbDeserializer<SimplePojo> {
@Override
public SimplePojo deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
SimplePojo simplePojo = new SimplePojo();
parser.next();
parser.next();
simplePojo.setStringProperty(parser.getString());
return simplePojo;
}
}
public class SimplePojo {
private String stringProperty;
public String getStringProperty() {
return stringProperty;
}
public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
} |
I have tried your test and the deserializer is called 2 times, so I have rewritten your test using my deserializer and my pojo. the result of the test is the same, an array of 3 object and deserializer called just once.
Is there an alternative way to access to object data? Do I need to use parser.getString() as you have done in your example? |
After debugging, I think that the problem is related to glassfish implementation of the JsonParser, so it isn't a yasson issue. Probably the @cpoels original issue is different from this, I have misunderstood becouse the effect was the same. |
This https://github.com/eclipse-ee4j/jsonp is glassfish JsonParser impl (the only one). I will take a look at your example later. |
yeah, what I want to say is that I think the problem is not inside the yasson but in jakarta.json lib as you suggested me previously. Ok, I will waiting for your feedback. Thank you |
as you probably already know, the problem reported by @cpoels should be the same because the |
Thank you @notarmara, I now see the problem. Its not because of a bug in jsonp. You can also do: SimplePojo sp = ctx.deserialize(SimplePojo.class, parser);
//instead of
JsonObject obj = parser.getObject(); |
Closing this issue since @bravehorsie delivered the fix in #271 |
Hello together,
I am currently struggling with deserializing a List using a custom deserializer for the generic type of the list. I think that I am missing something obvious but I can't get it to work and I didn't find any issue related to mine.
My simplified implementation:
In my test I am executing a GET as followed:
But I only get a List with one entry. My deserializer is not called a second time.
I am using Yasson 1.0.3 in a Wildfly 14 container.
I appreciate any hint!
The text was updated successfully, but these errors were encountered: