Can not deserialize instance of my package out of START_ARRAY token

lakshman kumar

I'm m currently having trouble connecting to my webservice on android.I use jackson-core/databind/annotation-2.2.4 and Spring RESTWebService. If I access the URL from browser I can see the JSON response: (server return List\Shop\ looks like:)

[{"id":1,"product_tmpl_id":1,"message_last_post":null,"ean13":null,"default_code":null,"name_template":"Service","image_variant":null,"active":true,"create_uid":1,"create_date":1463633587963,"write_date":1463633587963,"write_uid":1}]

From a Client endpoint (Android application) I receive this error message:

06-14 15:18:34.702 14597-14639/? E/MainActivity: Could not read JSON: Can not deserialize instance of stpi.com.rest.Products out of START_ARRAY token
at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41da0398; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of stpi.com.rest.Products out of START_ARRAY token
at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41da0398; line: 1, column: 1]
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of stpi.com.rest.Products out of START_ARRAY token
at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41da0398; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of stpi.com.rest.Products out of START_ARRAY token
at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41da0398; line: 1, column: 1]
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:126)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:237)
at stpi.com.rest.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:83)
at stpi.com.rest.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:76)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of stpi.com.rest.Products out of START_ARRAY token
at [Source: com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream@41da0398; line: 1, column: 1]
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:691)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:685)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1215)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:126)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2993)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2158)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:123)
... 13 more
06-14 15:18:34.707 14597-14597/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: stpi.com.rest, PID: 14597
java.lang.NullPointerException
at stpi.com.rest.MainActivity$HttpRequestTask.onPostExecute(MainActivity.java:96)
at stpi.com.rest.MainActivity$HttpRequestTask.onPostExecute(MainActivity.java:76)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)

My main activity in android app:

package stpi.com.rest;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        new HttpRequestTask().execute();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_refresh) {
            new HttpRequestTask().execute();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.content_main, container, false);
            return rootView;
        }
    }


    private class HttpRequestTask extends AsyncTask<Void, Void, Products> {
        @Override
        protected Products doInBackground(Void... params) {
            try {
                final String url = "http://164.164.36.11:443/seis/productController/getProduct";
                RestTemplate restTemplate = new RestTemplate();
                restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
                Products greeting = restTemplate.getForObject(url, Products.class);
                return greeting;
            } catch (Exception e) {
                Log.e("MainActivity", e.getMessage(), e);
            }

            return null;
        }

        @Override
        protected void onPostExecute(Products greeting) {
            TextView greetingIdText = (TextView) findViewById(R.id.id_value);
            TextView greetingContentText = (TextView) findViewById(R.id.content_value);
            greetingIdText.setText(greeting.getId());
            greetingContentText.setText(greeting.getname_template());
            greetingContentText.setText(greeting.getproduct_tmpl_id());
            greetingContentText.setText(greeting.getmessage_last_post());
            greetingContentText.setText(greeting.getean13());
            greetingContentText.setText(greeting.getdefault_code());
            greetingContentText.setText(greeting.getimage_variant());
            greetingContentText.setText(greeting.getactive());
            greetingContentText.setText(greeting.getcreate_uid());
            greetingContentText.setText(greeting.getcreate_date());
            greetingContentText.setText(greeting.getwrite_date());
            greetingContentText.setText(greeting.getwrite_uid());
        }

    }

}

This is the Other class Product where I Add the id,rest variables and getters.

package stpi.com.rest;

/**
 * Created by Admin on 6/14/2016.
 */
public class Products {

    private String id;
    private String name_template;
    private String product_tmpl_id;
    private String message_last_post;
    private String ean13;
    private String default_code;
    private String image_variant;
    private String active;
    private String create_uid;
    private String create_date;
    private String write_date;
    private String write_uid;


    public String getId() {
        return this.id;
    }

    public String getname_template() {
        return this.name_template;
    }

    public String getproduct_tmpl_id() {
        return this.product_tmpl_id;
    }

    public String getmessage_last_post() {
        return this.message_last_post;
    }

    public String getean13() {
        return this.ean13;
    }

    public String getdefault_code() {
        return this.default_code;
    }

    public String getimage_variant() {
        return this.image_variant;
    }
    public String getactive() {
        return this.active;
    }

    public String getcreate_uid() {
        return this.create_uid;
    }

    public String getcreate_date() {
        return this.create_date;
    }

    public String getwrite_date() {
        return this.write_date;
    }

    public String getwrite_uid() {
        return this.write_uid;
    }



}

Can anyone help me to solve this issue?

lakshman kumar

As we are getting object collection to get single object I had used Product[] and it worked correctly.

private class HttpRequestTask extends AsyncTask<Void, Void, Products> {
        Products[] greeting;
        @Override
        protected Products doInBackground(Void... params) {
            try {
                final String url = "http://164.164.36.11:443/seis/productController/getProduct";
                RestTemplate restTemplate = new RestTemplate();
                restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
                greeting = restTemplate.getForObject(url, Products[].class);

                return greeting[0];
            } catch (Exception e) {
                Log.e("MainActivity", e.getMessage(), e);
            }

            return null;
        }

        @Override
        protected void onPostExecute(Products greeting) {
            TextView greetingIdText = (TextView) findViewById(R.id.id_value);
            TextView greetingContentText = (TextView) findViewById(R.id.content_value);
            Log.i("post exe active", greeting.getname_template());
            greetingIdText.setText(greeting.getId());
            greetingContentText.setText(greeting.getname_template());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

From Java

Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

From Java

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

From Java

JsonMappingException: out of START_ARRAY token

From Dev

Json Mapping Exception can not deserialize instance out of START_ARRAY token

From Dev

Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT token

From Dev

Cannot deserialize instance of object out of START_ARRAY token in Spring Webservice

From Dev

Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

From Dev

Can not deserialize instance of JsonGen out of START_ARRAY token : newbee

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

From Dev

JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

From Dev

Can not deserialize instance of Object out of START_ARRAY token

From Dev

Ignore the "Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token" error

From Dev

Can not deserialize instance of my.package.name.PlaceData[] out of START_OBJECT token

From Dev

Can not deserialize instance of java.util.HashMap out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

Java REST API: Can not deserialize instance of Object out of START_ARRAY token

From Dev

Exception: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

From Dev

Can not serialize instance of class out of START_ARRAY token\n

From Dev

ObjectMapper fails to deserialize - cannot deserialize instance of .... out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

From Dev

Can not deserialize instance of Object out of START_ARRAY token

From Dev

Java REST API: Can not deserialize instance of Object out of START_ARRAY token

From Dev

Can not deserialize instance of SaleListDTO out of START_ARRAY token

Related Related

  1. 1

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

  2. 2

    Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

  3. 3

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

  4. 4

    JsonMappingException: out of START_ARRAY token

  5. 5

    Json Mapping Exception can not deserialize instance out of START_ARRAY token

  6. 6

    Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT token

  7. 7

    Cannot deserialize instance of object out of START_ARRAY token in Spring Webservice

  8. 8

    Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

  9. 9

    Can not deserialize instance of JsonGen out of START_ARRAY token : newbee

  10. 10

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

  11. 11

    JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

  12. 12

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

  13. 13

    Can not deserialize instance of Object out of START_ARRAY token

  14. 14

    Ignore the "Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token" error

  15. 15

    Can not deserialize instance of my.package.name.PlaceData[] out of START_OBJECT token

  16. 16

    Can not deserialize instance of java.util.HashMap out of START_ARRAY token

  17. 17

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  18. 18

    Java REST API: Can not deserialize instance of Object out of START_ARRAY token

  19. 19

    Exception: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

  20. 20

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

  21. 21

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  22. 22

    Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

  23. 23

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

  24. 24

    Can not serialize instance of class out of START_ARRAY token\n

  25. 25

    ObjectMapper fails to deserialize - cannot deserialize instance of .... out of START_ARRAY token

  26. 26

    JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

  27. 27

    Can not deserialize instance of Object out of START_ARRAY token

  28. 28

    Java REST API: Can not deserialize instance of Object out of START_ARRAY token

  29. 29

    Can not deserialize instance of SaleListDTO out of START_ARRAY token

HotTag

Archive