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 9177883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:25:42+00:00 2026-06-17T17:25:42+00:00

I have a json based REST Web Service implemented using: Jetty, Jersey, Jersey-JSON using

  • 0

I have a json based REST Web Service implemented using:
Jetty, Jersey, Jersey-JSON using Jackson.

One of my methods receives a Person instance, which has a field of type List<String>.
i.e.:

Public class Person {
    List<String> names;
}

If I call it with an array of names, all works ok! e.g.:

{ "names" : [ "Jhon", "Doe" ] }

But if the person has only one name, my client creates a single value element, e.g.:

{ "names" : "Jhon" } 

When I try to call the service with a single value, I get an exception:

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

Question:

How should I create/configure my web service, in order to be able to deserialize array field when they are sent to me as a single element.

—

I already read:

Jackson deserialization – with contained ArrayList<T>

and

How can I customize serialization of a list of JAXB objects to JSON?

and this that refer the last answer:

Jersey client can not deserializable json services – exception(can not deserialize instance)

Jaxb json missing brackets for one element array

But none of those fix the problem.

Thank you in advance!

  • 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-06-17T17:25:43+00:00Added an answer on June 17, 2026 at 5:25 pm

    After a long day, and another… after reading lots of wikis and faqs, it finally works.

    What I did:

    1. Use Jackson
    2. Force Jackson providers usage
    3. Define custom deserializer
    4. activate the ACCEPT_SINGLE_VALUE_AS_ARRAY flag
    5. Fix dependencies

    The story:

    I was using Jersey 1.13 that uses (I belive) jaxb by default.

    I changed it to use Jackson

    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    

    as described at:

    https://stackoverflow.com/a/13895768/660990

    This made my jersey use jackson, but the problem remains; jackson can’t deserializer the array yet.

    I forced the usage of Jackson providers:

    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>
            your.project.packages;
            org.codehaus.jackson.jaxrs</param-value>
    </init-param>
    

    https://stackoverflow.com/a/3143214/660990

    Was a needed step, but not enough. It’s necessary to activate the ACCEPT_SINGLE_VALUE_AS_ARRAY flag.

    ObjectMapper objectMapper;
    objectMapper = new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    

    I needed define custom deserializer

    public class MyResolver implements ContextResolver<ObjectMapper> {
    
    @Override
        public ObjectMapper getContext(final Class<?> objectType) {
            ...            
            return objectMapper;
        }
    }
    

    in order to do that:

    Customizing-ObjectMapper

    After doing all of this it still didn’t work…

    After some more search time, I found:

    Jackson 2.0 with Jersey 1.12

    That discusses dependencies problems..

    This reveled my problem, Jersey v1.13 ships with Jackson v1.9.2 I need Jackson v2.0

    I removed dependency for jersey-json, because it included jackson 1.9.2:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
    </dependency>
    

    And directly declared dependency for:

    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>
    

    Reference:

    jackson-jaxrs-json-provider

    Note: this change removes the Jersey ability to use Jaxb or jettison.

    Off topic, may be interesting for someone:

    Configure Jersey/Jackson to NOT use @XmlElement field annotation for JSON field naming

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

Sidebar

Related Questions

All, We are using ASP.NET Web API where we have a REST based service
am new to Json so a little green. I have a Rest Based Service
I have a REST service built using Jersey. I want to be able to
We have a web application providing a service using a simple REST interface (GET/POST
I have created a rest architecture based web service in C# which will return
I have created simple web service for my website that generates some json based
I have a Jersey based Rest WS which outputs JSON. I am implementing a
I have to call the web service using java script? e.g. I'm creating one
So I have a REST based service which is hosted at http://localhost:35798/RestServiceImpl.svc/json/567 If I
I have a web app with a clean RESTful JSON API, based on Rails

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.