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

ObjectMapper.copy does not preserve MappingJsonFactory features #913

Closed
dsw2127 opened this issue Sep 1, 2015 · 0 comments
Closed

ObjectMapper.copy does not preserve MappingJsonFactory features #913

dsw2127 opened this issue Sep 1, 2015 · 0 comments

Comments

@dsw2127
Copy link
Contributor

dsw2127 commented Sep 1, 2015

ObjectMapper's copy method does not correctly copy Features if constructed with a MappingJsonFactory, which is the default for the ObjectMapper no-arg constructor.

This issue was fixed for JsonFactory FasterXML/jackson-core@7b796a8 , but not for the default factory of ObjectMapper.

For example:

public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(Feature.ALLOW_COMMENTS, true);
    System.out.println("Expecting true: " + mapper.getFactory().isEnabled(Feature.ALLOW_COMMENTS));

    System.out.println("Expecting 9: " + mapper.readValue("//test\n9", Integer.class));
    ObjectMapper copy = mapper.copy();
    System.out.println("Expecting true: " + copy.isEnabled(Feature.ALLOW_COMMENTS));
    System.out.println("Expecting 9: " + copy.readValue("//test\n9", Integer.class));
}

This prints out:
Expecting true: true
Expecting 9: 9
Expecting true: false
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)
at [Source: //test
9; line: 1, column: 2]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1581)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:533)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:462)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipComment(ReaderBasedJsonParser.java:2099)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd2(ReaderBasedJsonParser.java:2074)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2025)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:577)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3742)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3687)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2714)
at foo.JacksonTest.main(JacksonTest.java:20)

cowtowncoder added a commit that referenced this issue Sep 10, 2015
Fix #913: Properly copy MappingJsonFactory features
cowtowncoder added a commit that referenced this issue Sep 10, 2015
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

1 participant