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

Parsing case insensetive fields #1036

Closed
DmRomantsov opened this issue Dec 4, 2015 · 3 comments
Closed

Parsing case insensetive fields #1036

DmRomantsov opened this issue Dec 4, 2015 · 3 comments
Milestone

Comments

@DmRomantsov
Copy link

It's works by using jackson-databind version 2.5.0, but doesn't work in 2.6.3

private final String json = "{\"ErrorCode\":2,\"DebugMessage\":\"Signature not valid!\"}";

@Test
public void testParsing() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    BaseResponse response = mapper.readValue(json, BaseResponse.class);
    Assert.assertEquals(response.getDebugMessage(), "Signature not valid!");
    Assert.assertEquals(response.getErrorCode(), 2);
}

static class BaseResponse {

    protected int errorCode;
    protected String debugMessage;

    public String getDebugMessage() {
        return debugMessage;
    }

    public void setDebugMessage(String debugMessage) {
        this.debugMessage = debugMessage;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }
}

StackTrace:
java.util.NoSuchElementException: No entry 'debugMessage' found, can't replace
at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.replace(BeanPropertyMap.java:254)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:478)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:296)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:461)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3838)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3732)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2726)
at JacksonTest.testParsing(JacksonTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

@cowtowncoder cowtowncoder added this to the 2.6.4 milestone Dec 7, 2015
@cowtowncoder
Copy link
Member

Thank you for reporting this -- fixed in upcoming 2.6.4 release.

@TorosyanV
Copy link

I have same error. And this is simple json that can't deserialize.
My POJO is

package onfilm.DTOs;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ImdbDataDTO {
    @JsonProperty("imdbId")
    private String imdbId;

    private String title;

    private String year;

    private String rated;

    private String relesed;

    private String runtime;

    private String genre;

    private String director;

    private String writer;

    private String actors;

    private String plot;

    private String language;

    private String country;

    private String awards;

    private String poster;

    private String mertascore;

    @JsonProperty("imdbRating")
    private String imdbRating;

    @JsonProperty("imdbVotes")
    private String imdbVotes;

    private String type;

    public String getImdbId() {
        return imdbId;
    }

    public void setImdbId(String imdbId) {
        this.imdbId = imdbId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getRated() {
        return rated;
    }

    public void setRated(String rated) {
        this.rated = rated;
    }

    public String getRelesed() {
        return relesed;
    }

    public void setRelesed(String relesed) {
        this.relesed = relesed;
    }

    public String getRuntime() {
        return runtime;
    }

    public void setRuntime(String runtime) {
        this.runtime = runtime;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getWriter() {
        return writer;
    }

    public void setWriter(String writer) {
        this.writer = writer;
    }

    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }

    public String getPlot() {
        return plot;
    }

    public void setPlot(String plot) {
        this.plot = plot;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getAwards() {
        return awards;
    }

    public void setAwards(String awards) {
        this.awards = awards;
    }

    public String getPoster() {
        return poster;
    }

    public void setPoster(String poster) {
        this.poster = poster;
    }

    public String getMertascore() {
        return mertascore;
    }

    public void setMertascore(String mertascore) {
        this.mertascore = mertascore;
    }

    public String getImdbRating() {
        return imdbRating;
    }

    public void setImdbRating(String imdbRating) {
        this.imdbRating = imdbRating;
    }

    public String getImdbVotes() {
        return imdbVotes;
    }

    public void setImdbVotes(String imdbVotes) {
        this.imdbVotes = imdbVotes;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

}

and JSON is

    {
      "Title": "'Tis the Season for Love",
      "Year": "2015",
      "Rated": "TV-G",
      "Released": "01 Nov 2015",
      "Runtime": "98 min",
      "Genre": "Comedy, Romance",
      "Director": "Terry Ingram",
      "Writer": "Nina Weinman",
      "Actors": "Sarah Lancaster, Brendan Penny, Gwynyth Walsh, Andrew Francis",
      "Plot": "Beth Baker is an out-of-work actress stuck in New York City without her friends at Christmas time. She decides to return home to the quaint small town she escaped 10 years before and finds a place far different than the hamlet she left. She suddenly finds performing possibilities and even romance.",
      "Language": "English",
      "Country": "Canada",
      "Awards": "N/A",
      "Poster": "N/A",
      "Metascore": "N/A",
      "imdbRating": "6.6",
      "imdbVotes": "340",
      "imdbID": "tt5056034",
      "Type": "movie",
      "Response": "True"
    }

@cowtowncoder
Copy link
Member

@TorosyanV could you please file a new issue for this? Since the original problem (the specific case) was resolved, as per unit test, this may well be related (assuming you are using version 2.6.4), but the underlying fix is different. You can add a reference to this issue in the new one.

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

3 participants