杰克逊序列化通用但未反序列化

时间:2018-05-25 17:56:27

标签: java jackson deserialization

我怎样才能做到这一点?我看看其他问题,但我无法弄清楚如何。其实我对杰克森不太了解。也许“lombok”导致问题。提前谢谢你。

    @Data class A{String b;}
    @Data class B<T>{ T c; }


    A a1 = new A();
    a1.setB("sa");
    B<A> s = new B<A>();
    s.c = a1;

    ObjectMapper objectMapper = new ObjectMapper();

    String sj = objectMapper.writeValueAsString(s);
    System.out.println(sj); // {"c":{"b":"sa"}} 

    B<A> ba = objectMapper.readerFor(new TypeReference<B<A>>() {
    })
            .readValue(sj); // this is not working 

给出了这个错误:

    com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize 
    EmbeddedTest$1B (of type local/anonymous) as a Bean.

0 个答案:

没有答案