Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6768061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:01:42+00:00 2026-05-26T15:01:42+00:00

I am using Jackson to serialize a JAXB annotated object into a map object.

  • 0

I am using Jackson to serialize a JAXB annotated object into a map object. Here is some code to illustrate my problem:

    public class Test {

    @XmlAccessorType(XmlAccessType.NONE)
    public static class Inner {
        @XmlAttribute
        public int foo;
    }

    @XmlAccessorType(XmlAccessType.NONE)
    public static class Outer {
        @XmlAttribute
        public String bar;

        @XmlElement
        public Inner in;
    }

    public static void main(String[] args) throws Exception {
        ObjectMapper mapper = getMapper();

        mapper.enableDefaultTyping();

        Inner in = new Inner();
        in.foo = 42;
        Outer out = new Outer();
        out.in = in;
        out.bar = "thecakeisalie";

        Object o = mapper.convertValue(out, TreeMap.class);
        System.out.println(o);
    }

    public static ObjectMapper getMapper() {
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
        mapper.setAnnotationIntrospector(introspector);
        return mapper;
    }
}

This results in the following error:

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Object
 at [Source: N/A; line: -1, column: -1]
    at org.codehaus.jackson.map.ObjectMapper._convert(ObjectMapper.java:2493)
    at org.codehaus.jackson.map.ObjectMapper.convertValue(ObjectMapper.java:2459)
    at com.example.test.Test.main(Test.java:49)
Caused by: org.codehaus.jackson.map.JsonMappingException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.lang.Object
 at [Source: N/A; line: -1, column: -1]
    at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.wrongTokenException(StdDeserializationContext.java:261)
    at org.codehaus.jackson.map.jsontype.impl.AsArrayTypeDeserializer._locateTypeId(AsArrayTypeDeserializer.java:100)
    at org.codehaus.jackson.map.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:86)
    at org.codehaus.jackson.map.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromAny(AsArrayTypeDeserializer.java:69)
    at org.codehaus.jackson.map.deser.std.UntypedObjectDeserializer.deserializeWithType(UntypedObjectDeserializer.java:106)
    at org.codehaus.jackson.map.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:321)
    at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:249)
    at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:33)
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2695)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
    at org.codehaus.jackson.map.ObjectMapper._convert(ObjectMapper.java:2489)
    ... 2 more

If the line mapper.enableDefaultTyping(); is omitted, the code works and outputs the following:

{bar=thecakeisalie, in={foo=42}}

If I use the mapper to serialize to json, it will work with default typing.

Is default typing incompatible with object conversions, or am I using it wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:01:42+00:00Added an answer on May 26, 2026 at 3:01 pm

    Ok. Hmmh. The problem stems from sort of incompatible usage: what happens is that when serializing, default typing will only add type information as per its configuration, and in this case type information is not included (types are not abstract, nor declared as java.lang.Object).
    But when deserializing (as part of conversion), result type expects type information, since nominal type is TreeMap<Object,Object>; and that’s where exception comes from.

    But since you are converting to a Map — which is essentially an “untyped” type — you are best off just not enabling default typing. That type information would be discarded anyway.

    Or, if you really want to see that included type information, you need to do two-phase processing: serialize with default typing enabled (using mapper that has it enabled), and deserialize as TreeMap, with ObjectMapper that has default typing disabled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am serializing and deserializing following domain object to JSON using Jackson 1.8.3 public
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I am using Jackson library's ObjectMapper for deserializing JSON into Java objects. I am
I'm having trouble getting Jackson to correctly deserialize json into an object when calling
I'm using the Streaming API JsonParser of the Jackson library to do some custom
I'm running into a problem with Jackson where it does not respect the @JsonTypeInfo
Typefactory class at jackson has many deprecated methods inside it. I am using it
I'm trying to use Jackson to deserialize some JSON originally created using Jackson. The
I am using Jackson 1.8.3 in a Spring application to map Java Objects to
I am trying to deserialize/map the below JSON to List<Bill > java object using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.