-
Notifications
You must be signed in to change notification settings - Fork 21
Cannot read some "pretty" documents #60
Comments
Here is the complete repro Junit test: import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
class FooList {
public List<Object> foos ;
}
public class AfterburnerIssue60Test {
String content =
"{\n" +
" \"foos\" :\n" +
" [\n" +
" ]\n" +
"}";
File filename = new File("foo.json") ;
@Before
public void setup() throws IOException {
try (FileWriter writer = new FileWriter(filename)) {
writer.write(content);
}
}
@Test
public void testMapperString() throws IOException {
ObjectMapper mapper = new ObjectMapper() ;
mapper.readValue(content, FooList.class) ;
}
@Test
public void testMapperFile() throws IOException {
ObjectMapper mapper = new ObjectMapper() ;
mapper.readValue(filename, FooList.class) ;
}
@Test
public void testMapperReader() throws IOException {
ObjectMapper mapper = new ObjectMapper() ;
mapper.readValue(new StringReader(content), FooList.class) ;
}
@Test
public void testMapperStream() throws IOException {
ObjectMapper mapper = new ObjectMapper() ;
mapper.readValue(new ByteArrayInputStream(content.getBytes()), FooList.class) ;
}
@Test
public void testBurnerString() throws IOException {
ObjectMapper burner = new ObjectMapper().registerModule(new AfterburnerModule()) ;
burner.readValue(content, FooList.class) ;
}
@Test
public void testBurnerFile() throws IOException {
ObjectMapper burner = new ObjectMapper().registerModule(new AfterburnerModule()) ;
burner.readValue(filename, FooList.class) ;
}
@Test
public void testBurnerReader() throws IOException {
ObjectMapper burner = new ObjectMapper().registerModule(new AfterburnerModule()) ;
burner.readValue(new StringReader(content), FooList.class) ;
}
@Test
public void testBurnerStream() throws IOException {
ObjectMapper burner = new ObjectMapper().registerModule(new AfterburnerModule()) ;
burner.readValue(new ByteArrayInputStream(content.getBytes()), FooList.class) ;
}
} and the results:
Hope this helps... |
Very interesting... thank you for reporting this, with a unit test. I suspect this is due to Afterburner calling slightly different parsing methods, and the actual issue being within JSON parser (probably within |
Yes, I tried to understand the problem using the debugger, but the solution was not obvious for me ... |
I can reproduce the problem locally, and it does indeed only affect byte-backed parser, which explain why some other sources (like |
Thank you very much ! |
Confirmed : 2.6.3 release solves my real-life use case. |
I'm facing an issue reading a pretty-printed document from a file with afterburner 2.6.2.
The input is a valid JSON document, but deserialization fails with a message saying that a colon is not found:
The document is as follow (please note the space before the colon):
{ "foos" : [ ] }
and the java code looks like this :
Using a raw ObjectMapper, there is no error reading a value from any source (String, File, Reader, Stream). However, after registering the AfterburnerModule, the deserialization fails reading from a File or a Stream (but other sources are ok...)
If you edit the document and remove the space before the colon, then everything is fine with Afterburner. Of course, this is only feasible for testing purpose, in real life I can't change the formatting on the server producing the JSON document...
Here is the full stack trace:
The text was updated successfully, but these errors were encountered: