-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Why exception occur?
com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT),
expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class junk.deserializeTest.RisonTest$Obj1
at [Source: (StringReader); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException(DeserializationContext.java:1646)
at com.fasterxml.jackson.databind.DeserializationContext.reportWrongTokenException(DeserializationContext.java:1396)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._locateTypeId(AsArrayTypeDeserializer.java:141)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:96)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromObject(AsArrayTypeDeserializer.java:61)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:1197)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4482)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3434)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3402)
at junk.deserializeTest.RisonTest.test(RisonTest.java:143)
public class RisonTest {
public static class Obj1 {
private int i = 1;
private Obj2 o2 = new Obj2();
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + i;
result = prime * result + ((o2 == null) ? 0 : o2.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Obj1 other = (Obj1) obj;
if (i != other.i)
return false;
if (o2 == null) {
if (other.o2 != null)
return false;
} else if (!o2.equals(other.o2))
return false;
return true;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public Obj2 getO2() {
return o2;
}
public void setO2(Obj2 o2) {
this.o2 = o2;
}
}
public static class Obj2 {
private int i = 2;
private Obj3 o3 = new Obj3();
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + i;
result = prime * result + ((o3 == null) ? 0 : o3.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Obj2 other = (Obj2) obj;
if (i != other.i)
return false;
if (o3 == null) {
if (other.o3 != null)
return false;
} else if (!o3.equals(other.o3))
return false;
return true;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
public Obj3 getO3() {
return o3;
}
public void setO3(Obj3 o3) {
this.o3 = o3;
}
}
public static class Obj3 {
private int i = 3;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + i;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Obj3 other = (Obj3) obj;
if (i != other.i)
return false;
return true;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
}
@Test
public void test() throws Exception {
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder()
.allowIfBaseType(Obj1.class).allowIfBaseType(Obj2.class)
.allowIfBaseType(Obj3.class).build();
ObjectMapper O_RISON = new ObjectMapper(
new RisonFactory().enable(RisonGenerator.Feature.O_RISON)
.enable(RisonParser.Feature.O_RISON))
.activateDefaultTyping(ptv,
DefaultTyping.NON_FINAL);
Obj1 src = new Obj1();
String rison = O_RISON.writeValueAsString(src);
System.out.println(rison);
Obj1 o = O_RISON.readValue(rison, Obj1.class);
System.out.println(src.equals(o));
}
}
Metadata
Metadata
Assignees
Labels
No labels