Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.3
-
Fix Version/s: 1.3.1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
(from mailing list, reported by Mike P)
—
I have been working on a simple application using Jackson 1.2 and had Jaxb
annotation mapping working. However when I switch to Jackson 1.3, I get an
error on deserialization. It appears that Jackson is not finding fields in
a Jaxb generated class unless the field has an XmlElement annotation.
There was a previous bug like this (I forget the number) fixed in Jackson
1.2 but it appears to have reappeared in 1.3. Maybe I'm just missing some
new configuration I need to do in 1.3?
In 1.2 I get:
{
"temperature" : 2.5,
"targetScale" : "c"
}
2.5
In 1.3 I get:
DEBUG: findGettable for [method getTemperature, annotations: [null]],
invis: true
DEBUG: findGettable for [method getTargetScale, annotations: [null]],
invis: true
{
"temperature" : 2.5,
"targetScale" : "c"
}
Exception in thread "main" org.codehaus.jackson.map.JsonMappingException:
Unrecognized field "temperature" (Class
org.mpilone.spring.web.domain.messages.ConvertTemperature), not marked as
ignorable
at [Source: java.io.ByteArrayInputStream@1a5f739; line: 2, column: 3]
at
org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:159)
at
org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:174)
at
org.codehaus.jackson.map.deser.StdDeserializer.reportUnknownProperty(StdDeserializer.java:310)
at
org.codehaus.jackson.map.deser.StdDeserializer.handleUnknownProperty(StdDeserializer.java:296)
at
org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:487)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:344)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:271)
at
org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1142)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:871)
at JacksonTest.main(JacksonTest.java:43)
Test case is:
import java.io.*;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
import org.mpilone.spring.web.domain.messages.ConvertTemperature;
public class JacksonTest
{
public static void main(String[] args) throws JsonGenerationException,
JsonMappingException, IOException
}
------------------------
package org.mpilone.spring.web.domain.messages;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"temperature",
"targetScale"
})
@XmlRootElement(name = "ConvertTemperature")
public class ConvertTemperature {
protected float temperature;
@XmlElement(required = true)
protected String targetScale;
public float getTemperature()
{ return temperature; }public void setTemperature(float value)
{ this.temperature = value; }public String getTargetScale()
{ return targetScale; }public void setTargetScale(String value)
{ this.targetScale = value; }}
I can reproduce the problem, which is related to visibility of fields, and possibly a regression.
However, same test also fails for 1.2.1. Nonetheless it's a bug to fix, will fix in trunk, try to backport to 1.3.1 as well.