Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected a string but was BEGIN_OBJECT at line 1 column 2 #140

Open
darumaGit opened this issue Apr 17, 2018 · 1 comment
Open

Expected a string but was BEGIN_OBJECT at line 1 column 2 #140

darumaGit opened this issue Apr 17, 2018 · 1 comment

Comments

@darumaGit
Copy link

darumaGit commented Apr 17, 2018

That may be not an issue

Hello. I am using gwt-jackson. Parsing an object like {"name":"VALUE"} I get an error "Error at line 1 and column 2 of input <{"name": "AUSTRIA"}>.
I am trying to parse it into enum object like:

public enum Countries {
    AUSTRIA(2, 2, 1, 1, 1, 1),
    ......
    @JsonProperty(value = "name")
    private String name;

    public CountryRegions getName(){return valueOf(name);}

    public void setName(String name){this.name = name;}
}

Here is the mapper:
public interface CountryMapper extends ObjectMapper<Countries>{}
Mapper creation:
CountryMapper mapper = GWT.create(CountryMapper.class);
and
Countries country = mapper.read("{\"name\": \"AUSTRIA\"}");

I have tried without property, getter and setter in the enum - this also didn't help. The only way to parse it is to create a proxy model with string property and first parse json to that model.
I suppose the issue is in the enum.
What would be your suggestion? What do I do wrong?

@nmorel
Copy link
Owner

nmorel commented Apr 24, 2018

Hello,

Sorry for the late response.
You are creating a mapper directly on your enum.
The "json" should be the value directly :

Countries country = mapper.read("\"AUSTRIA\"");

If you have a json with {\"name\": \"AUSTRIA\"}, you should create a mapper on a class with a name property of type Countries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants