protected EndpointConfig initReader(ObjectMapper mapper) { // first common config if (_activeView != null) { _reader = mapper.readerWithView(_activeView); } else { _reader = mapper.reader(); } if (_rootName != null) { _reader = _reader.withRootName(_rootName); } // Then deser features if (_deserEnable != null) { _reader = _reader.withFeatures(_deserEnable); } if (_deserDisable != null) { _reader = _reader.withoutFeatures(_deserDisable); } /* Important: we are NOT to close the underlying stream after * mapping, so we need to instruct parser: */ _reader.getJsonFactory().disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); return this; }
public void testSimple() throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectReader jsonReader = mapper.reader(POJO.class); final String JSON = "{\"name\":\"Bob\", \"id\":3}"; byte[] doc = _smileDoc(JSON, true); ObjectReader detecting = jsonReader.withFormatDetection(jsonReader, jsonReader.with(new SmileFactory())); POJO pojo = detecting.readValue(doc); assertEquals(3, pojo.id); assertEquals("Bob", pojo.name); // let's verify it also works for plain JSON... pojo = detecting.readValue(JSON.getBytes("UTF-8")); assertEquals(3, pojo.id); assertEquals("Bob", pojo.name); }