You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Mark Struberg (JIRA)" <ji...@apache.org> on 2018/08/29 12:34:00 UTC

[jira] [Commented] (JOHNZON-169) @JsonbTypeDeserializer(xxxJsonbDeserializer.class) is not working properly

    [ https://issues.apache.org/jira/browse/JOHNZON-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16596268#comment-16596268 ] 

Mark Struberg commented on JOHNZON-169:
---------------------------------------

hiho! I've read through the spec and JavaDoc and I fear we have some gaps in both. I've now created a spec ticket for it [https://github.com/eclipse-ee4j/jsonb-api/issues/89.]

 

So far Johnzon supports annotating the field (or setter):
{code:java}
public class SomeStudentsList { 
  @JsonbTypeDeserializer(StudentDeserializer.class)
  private List<Student> students = new ArrayList<>(); 
} 
{code}

Note that this supports the case where you have a json for each Student. If you just have a String then you would need to use a `JsonbAdapter`.

> @JsonbTypeDeserializer(xxxJsonbDeserializer.class) is not working properly
> --------------------------------------------------------------------------
>
>                 Key: JOHNZON-169
>                 URL: https://issues.apache.org/jira/browse/JOHNZON-169
>             Project: Johnzon
>          Issue Type: Bug
>          Components: JSON-B
>    Affects Versions: 1.1.7
>         Environment: JDK8, Windows 10
>  
>            Reporter: Miroslav Nachev
>            Assignee: Mark Struberg
>            Priority: Blocker
>
> I have made my own JonsArray converter in JavaClass, which works properly when called alone. For this purpose, I have used an annotation:
> @JsonbTypeDeserializer(Student.StudentDeserializer.class)
> public class Student \{...}
> public static class StudentDeserializer implements JsonbDeserializer<Student> \{...}
> The problem comes, when this object Student is part of an array (List), that is located in another object:
> public class SomeStudentsList {
>  private List<Student> students = new ArrayList<>();
> }
> json=\{"students":[["Value-1","Value-2","Value-N"], ["Value-1","Value-2","Value-N"], ["Value-1","Value-2","Value-N"]]}
> The result exception is:
> Exception in thread "main" java.lang.UnsupportedOperationException: type class eu.nscenter.scilearn.manage.Student not supported
> at org.apache.johnzon.mapper.MappingParserImpl.buildArray(MappingParserImpl.java:602)
> at org.apache.johnzon.mapper.MappingParserImpl.toObject(MappingParserImpl.java:518)
> at org.apache.johnzon.mapper.MappingParserImpl.toValue(MappingParserImpl.java:699)
> at org.apache.johnzon.mapper.MappingParserImpl.mapCollection(MappingParserImpl.java:644)
> at org.apache.johnzon.mapper.MappingParserImpl.buildArray(MappingParserImpl.java:594)
> at org.apache.johnzon.mapper.MappingParserImpl.toObject(MappingParserImpl.java:518)
> at org.apache.johnzon.mapper.MappingParserImpl.toValue(MappingParserImpl.java:699)
> at org.apache.johnzon.mapper.MappingParserImpl.buildObject(MappingParserImpl.java:338)
> at org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:141)
> at org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:133)
> at org.apache.johnzon.mapper.MappingParserImpl.readObject(MappingParserImpl.java:125)
> at org.apache.johnzon.mapper.Mapper.mapObject(Mapper.java:254)
> at org.apache.johnzon.mapper.Mapper.readObject(Mapper.java:189)
> at org.apache.johnzon.mapper.Mapper.readObject(Mapper.java:184)
> at org.apache.johnzon.jsonb.JohnzonJsonb.fromJson(JohnzonJsonb.java:58)
> at eu.nscenter.scilearn.manage.StudentsList.main(StudentsList.java:118)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)