use of com.fasterxml.jackson.core.JsonParser in project opentsdb by OpenTSDB.
the class TestJSON method parseToStreamASCIIByte.
@Test
public void parseToStreamASCIIByte() throws Exception {
JsonParser jp = JSON.parseToStream("{\"utf\":\"aeriennes\",\"ascii\":\"aariennes\"}".getBytes());
HashMap<String, String> map = this.parseToMap(jp);
assertEquals("aeriennes", map.get("utf"));
assertEquals("aariennes", map.get("ascii"));
}
use of com.fasterxml.jackson.core.JsonParser in project opentsdb by OpenTSDB.
the class TestJSON method parseToMap.
/** Helper to parse an input stream into a map */
private HashMap<String, String> parseToMap(final InputStream is) throws Exception {
JsonParser jp = JSON.parseToStream(is);
HashMap<String, String> map = new HashMap<String, String>();
String field = "";
String value;
while (jp.nextToken() != null) {
if (jp.getCurrentToken() == JsonToken.FIELD_NAME && jp.getCurrentName() != null) {
field = jp.getCurrentName();
} else if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
value = jp.getText();
map.put(field, value);
}
}
return map;
}
use of com.fasterxml.jackson.core.JsonParser in project fastjson by alibaba.
the class JacksonPageModelParser method parse.
/**
* @param content
* @throws JsonParseException
* @throws IOException
*/
public PageInstance parse(String content) throws JsonParseException, IOException {
JsonFactory f = new JsonFactory();
JsonParser parser = f.createJsonParser(content);
// move to the start of the
JsonToken current = parser.nextToken();
// object
// get instanceId
String instanceId = getNextTextValue("sid", parser);
// get pageId
String pageId = getNextTextValue("cid", parser);
// move to field: segments
current = parser.nextToken();
assertExpectedFiled(parser.getCurrentName(), "segments", parser.getCurrentLocation());
PageInstance pageInstance = new PageInstance();
pageInstance.setCid(pageId);
pageInstance.setSid(Long.valueOf(instanceId));
pageInstance.setSegments(parseSegments(parser));
return pageInstance;
// 构建组件树,用于递归渲染
// pageInstance.buildComponentTree();
}
use of com.fasterxml.jackson.core.JsonParser in project immutables by immutables.
the class BsonEncoding method unwrapJsonable.
public static DBObject unwrapJsonable(String json) {
try {
JsonParser parser = JSON_FACTORY.createParser(json);
parser.nextToken();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BsonGenerator generator = BSON_FACTORY.createGenerator(outputStream);
generator.copyCurrentStructure(parser);
generator.close();
parser.close();
byte[] data = outputStream.toByteArray();
return (DBObject) new LazyDBCallback(null).createObject(data, 0);
} catch (IOException ex) {
throw Throwables.propagate(ex);
}
}
use of com.fasterxml.jackson.core.JsonParser in project rest.li by linkedin.
the class JacksonDataCodec method stringToList.
@Override
public DataList stringToList(String input) throws IOException {
final Parser parser = new Parser();
JsonParser jsonParser = null;
try {
jsonParser = _jsonFactory.createParser(input);
return parser.parse(jsonParser, DataList.class);
} catch (IOException e) {
throw e;
} finally {
closeJsonParserQuietly(jsonParser);
}
}
Aggregations