Java 类com.google.gson.JsonStreamParser 实例源码
项目:mycore
文件:MCRWCMSNavigationResource.java
@POST
@Path("save")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response save(String json) throws Exception {
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (!jsonStreamParser.hasNext()) {
return Response.status(Status.BAD_REQUEST).build();
}
JsonObject saveObject = jsonStreamParser.next().getAsJsonObject();
// get navigation
MCRNavigation newNavigation = MCRWCMSNavigationManager.fromJSON(saveObject);
// save navigation
MCRWCMSNavigationManager.save(newNavigation);
// save content
JsonArray items = saveObject.get(MCRWCMSNavigationProvider.JSON_ITEMS).getAsJsonArray();
getContentManager().save(items);
return Response.ok().build();
}
项目:mycore
文件:MCRCategUtils.java
public static HashMap<MCRCategoryID, String> getCategoryIDMap(String json) {
HashMap<MCRCategoryID, String> categories = new HashMap<>();
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (jsonStreamParser.hasNext()) {
JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
for (JsonElement jsonElement : saveObjArray) {
//jsonObject.item.id.rootid
JsonObject root = jsonElement.getAsJsonObject();
String rootId = root.getAsJsonObject("item").getAsJsonObject("id").getAsJsonPrimitive("rootid")
.getAsString();
String state = root.getAsJsonPrimitive("state").getAsString();
JsonElement parentIdJSON = root.get("parentId");
if (parentIdJSON != null && parentIdJSON.isJsonPrimitive()
&& "_placeboid_".equals(parentIdJSON.getAsString())) {
state = "new";
}
categories.put(MCRCategoryID.rootID(rootId), state);
}
} else {
return null;
}
return categories;
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_add1417() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings_add1417");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("one").toCharArray());
writer.write(gson.toJson("one").toCharArray());
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_add1418() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings_add1418");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("one").toCharArray());
writer.write(gson.toJson("two").toCharArray());
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_add1415() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_add1415");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_add1416() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_add1416");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(2 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1921() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1921");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 0 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1922() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1922");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , false , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1923() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1923");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "foo");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1924() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1924");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(1 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1925() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1925");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 1 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1926() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1926");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , true , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects_literalMutation1927() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_literalMutation1927");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
writer.write(gson.toJson(expectedOne).toCharArray());
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "foo");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_remove1171() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_remove1171");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoObjects_remove1172() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoObjects_remove1172");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
TestTypes.BagOfPrimitives expectedOne = new TestTypes.BagOfPrimitives(1 , 1 , true , "one");
TestTypes.BagOfPrimitives expectedTwo = new TestTypes.BagOfPrimitives(2 , 2 , false , "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
TestTypes.BagOfPrimitives actualOne = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2391,actualOne.stringValue);
TestTypes.BagOfPrimitives actualTwo = gson.fromJson(parser.next(), TestTypes.BagOfPrimitives.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2392,actualTwo.stringValue);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2394,parser,2393,parser.hasNext());
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:RaspberryPiBeaconParser
文件:TestBeaconSerialization.java
@Test
public void testGetMessageTypeTime() {
Gson gson = new Gson();
String json = "{\n" +
" \"scannerID\": \"Room203\",\n" +
" \"uuid\": \"DAF246CEF20311E4B116123B93F75CBA\",\n" +
" \"code\": 533,\n" +
" \"manufacturer\": 19456,\n" +
" \"major\": 203,\n" +
" \"minor\": 20,\n" +
" \"power\": -62,\n" +
" \"calibratedPower\": -62,\n" +
" \"rssi\": -67,\n" +
" \"messageType\": 1,\n" +
" \"time\": 1426016481227\n" +
"}";
JsonStreamParser parser = new JsonStreamParser(json);
JsonElement jse = parser.next();
JsonPrimitive messageType = jse.getAsJsonObject().getAsJsonPrimitive("messageType");
System.out.printf("jse.messageType = %d\n", messageType.getAsInt());
JsonPrimitive time = jse.getAsJsonObject().getAsJsonPrimitive("time");
System.out.printf("jse.time = %d\n", time.getAsLong());
}
项目:bandcamp-api
文件:JSONUtil.java
public static List<JsonObject> getTrackInfo(String json)
{
Gson gson = new Gson();
List<JsonObject> jsonTrackList = new ArrayList<JsonObject>();
JsonStreamParser parser = new JsonStreamParser( new StringReader(json.replace("},{", "}{")));
while (parser.hasNext())
{
jsonTrackList.add(gson.fromJson(parser.next(),JsonObject.class));
}
return jsonTrackList;
}
项目:mycore
文件:MCRClassificationEditorResource.java
@POST
@Path("save")
@MCRRestrictedAccess(MCRClassificationWritePermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response save(String json) {
JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
if (jsonStreamParser.hasNext()) {
JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
List<JsonObject> saveList = new ArrayList<>();
for (JsonElement jsonElement : saveObjArray) {
saveList.add(jsonElement.getAsJsonObject());
}
saveList.sort(new IndexComperator());
for (JsonObject jsonObject : saveList) {
String status = getStatus(jsonObject);
SaveElement categ = getCateg(jsonObject);
MCRJSONCategory parsedCateg = parseJson(categ.getJson());
if ("update".equals(status)) {
new UpdateOp(parsedCateg, jsonObject).run();
} else if ("delete".equals(status)) {
deleteCateg(categ.getJson());
} else {
return Response.status(Status.BAD_REQUEST).build();
}
}
// Status.CONFLICT
return Response.status(Status.OK).build();
} else {
return Response.status(Status.BAD_REQUEST).build();
}
}
项目:polyguice
文件:JsonConfiguration.java
private void load(Reader in) {
configTab = new HashMap<>();
JsonStreamParser parser = new JsonStreamParser(in);
JsonElement root = null;
if(parser.hasNext()) {
root = parser.next();
}
if(root != null && root.isJsonObject()) {
flatten(null, root);
}
LOGGER.debug("json configuration loaded: {}", configTab);
}
项目:che
文件:JsonMessageReader.java
/**
* @param source source of messages in JSON format
* @param messageClass class of the message object where JSON messages should be parsed. Because
* of erasure of generic information in runtime in some cases we can't get parameter class of
* current class.
*/
public JsonMessageReader(InputStream source, Class<T> messageClass) {
// we need to push back only 1 char, read more further
this.reader = new PushbackReader(new InputStreamReader(source), 1);
this.streamParser = new JsonStreamParser(reader);
this.messageClass = messageClass;
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("foo").toCharArray());
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings_literalMutation1929() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings_literalMutation1929");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("one").toCharArray());
writer.write(gson.toJson("foo").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_remove1173() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings_remove1173");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier
文件:ReadersWritersTest.java
@Test(timeout = 1000)
public void testReadWriteTwoStrings_remove1174() throws IOException {
fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testReadWriteTwoStrings_remove1174");
Gson gson = new Gson();
CharArrayWriter writer = new CharArrayWriter();
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2395,actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2396,actualTwo);
fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:RaspberryPiBeaconParser
文件:JsonEventStream.java
public void init(String dataSet) throws IOException {
// Get the dataSet input stream directly from git
URL gitURL = new URL("https://github.com/starksm64/RaspberryPiBeaconParser/blob/master/data/"+dataSet+"?raw=true");
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
reader = new InputStreamReader(gzip);
jsp = new JsonStreamParser(reader);
}
项目:RaspberryPiBeaconParser
文件:EntryExitEvents.java
TestSpliterator() throws IOException {
String dataSet = "FourScannersRun1-2015-03-10.json.gz";
// Get the dataSet input stream directly from git
URL gitURL = new URL("file:/Users/starksm/Dev/IoT/BLE/RaspberryPiBeaconParser/data/" + dataSet);
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzip);
gson = new Gson();
jsp = new JsonStreamParser(reader);
}
项目:RaspberryPiBeaconParser
文件:EntryExitEvents.java
static JsonStreamParser getDataSetParser(String dataSet) throws IOException {
// Get the dataSet input stream directly from git
URL gitURL = new URL("file:/Users/starksm/Dev/IoT/BLE/RaspberryPiBeaconParser/data/" + dataSet);
InputStream is = gitURL.openStream();
GZIPInputStream gzip = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzip);
JsonStreamParser jsp = new JsonStreamParser(reader);
return jsp;
}
项目:RaspberryPiBeaconParser
文件:EntryExitEvents.java
public static void main(String[] args) throws Exception {
String dataSet = "FourScannersRun1-2015-03-13.json.gz";
//String dataSet = "FourScannersBeacon5Run2-2015-03-13.json.gz";
JsonStreamParser jsp = getDataSetParser(dataSet);
List<Beacon> windowEvents = averageEvents(jsp);
Comparator<Beacon> cmp = (o1, o2) -> {
int compare = o1.getMinor() - o2.getMinor();
if(compare == 0) {
compare = (int) (o1.getTime() - o2.getTime());
}
return compare;
};
Collections.sort(windowEvents, cmp);
dumpToFile(windowEvents, "averageEvents.log");
// Break the sequence of events into a map of events by the beacon tag
HashMap<Integer, List<Beacon>> eventsByBeacon = new HashMap<>();
windowEvents.forEach(b -> {
int tag = b.getMinor();
List<Beacon> events = eventsByBeacon.get(tag);
if(events == null) {
events = new ArrayList<Beacon>();
eventsByBeacon.put(tag, events);
}
events.add(b);
}
);
// Now generate exit/entry events for each beacon
for(List<Beacon> beaconEvents : eventsByBeacon.values()) {
generateEntryExitEvents(beaconEvents);
}
}
项目:RaspberryPiBeaconParser
文件:TestSendRecv.java
@Test
public void testReadJsonFile() throws Exception {
FileReader fr = new FileReader("/tmp/testWriteJson.json");
Gson gson = new Gson();
JsonStreamParser jsp = new JsonStreamParser(fr);
int count = 0;
while (jsp.hasNext()) {
JsonElement jse = jsp.next();
Beacon beacon = gson.fromJson(jse, Beacon.class);
System.out.printf("%d: %s\n", count++, beacon);
}
fr.close();
}
项目:RaspberryPiBeaconParser
文件:TestBeaconSerialization.java
@Test
public void testReadJson() throws Exception {
FileReader fr = new FileReader("/tmp/testWriteJson.json");
Gson gson = new Gson();
JsonStreamParser parser = new JsonStreamParser(fr);
while(parser.hasNext()) {
JsonElement jse = parser.next();
Beacon beacon = gson.fromJson(jse, Beacon.class);
System.out.printf("Beacon from json:%s\n", beacon);
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parseOnly(File file, Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(new FileReader(file));
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parseOnly(Reader reader, Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(reader);
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:jsr353-benchmark
文件:GsonParser.java
@Override
public void parseOnly(InputStream in, Blackhole bh) throws Exception {
JsonStreamParser jsp = new JsonStreamParser(new InputStreamReader(in));
while (jsp.hasNext()) {
bh.consume(jsp.next());
}
}
项目:LungPostProcessor
文件:JSONExtractor.java
/***
* Opens the input File
*/
private void openFile() {
try {
parser = new JsonStreamParser(new FileReader(inputPath));
} catch (FileNotFoundException e) {
System.err.println("Error openning file.");
e.printStackTrace();
}
}
项目:buck-cutom
文件:DefaultOnDiskBuildInfo.java
@Override
public ImmutableList<String> apply(String input) {
JsonElement element = new JsonStreamParser(input).next();
Preconditions.checkState(element.isJsonArray(),
"Value for %s should have been a JSON array but was %s.",
input,
element);
JsonArray array = element.getAsJsonArray();
ImmutableList.Builder<String> out = ImmutableList.builder();
for (JsonElement item : array) {
out.add(item.getAsString());
}
return out.build();
}
项目:gson
文件:ReadersWritersTest.java
public void testReadWriteTwoStrings() throws IOException {
Gson gson= new Gson();
CharArrayWriter writer= new CharArrayWriter();
writer.write(gson.toJson("one").toCharArray());
writer.write(gson.toJson("two").toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
String actualOne = gson.fromJson(parser.next(), String.class);
assertEquals("one", actualOne);
String actualTwo = gson.fromJson(parser.next(), String.class);
assertEquals("two", actualTwo);
}
项目:gson
文件:ReadersWritersTest.java
public void testReadWriteTwoObjects() throws IOException {
Gson gson= new Gson();
CharArrayWriter writer= new CharArrayWriter();
BagOfPrimitives expectedOne = new BagOfPrimitives(1, 1, true, "one");
writer.write(gson.toJson(expectedOne).toCharArray());
BagOfPrimitives expectedTwo = new BagOfPrimitives(2, 2, false, "two");
writer.write(gson.toJson(expectedTwo).toCharArray());
CharArrayReader reader = new CharArrayReader(writer.toCharArray());
JsonStreamParser parser = new JsonStreamParser(reader);
BagOfPrimitives actualOne = gson.fromJson(parser.next(), BagOfPrimitives.class);
assertEquals("one", actualOne.stringValue);
BagOfPrimitives actualTwo = gson.fromJson(parser.next(), BagOfPrimitives.class);
assertEquals("two", actualTwo.stringValue);
assertFalse(parser.hasNext());
}
项目:MineIDE
文件:AvancedDataType.java
@Override
public T readStream(final DataInput data) throws IOException
{
return fromJson(new JsonStreamParser(data.readUTF()).next());
}
项目:ServiceCOLDCache
文件:TrackerClient.java
public void start() {
Runnable thread = new Runnable() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
Tracker tracker = new Tracker(getUser(), getHostName(),
getIp(), getOs(), System.currentTimeMillis(), getInitiator());
AutoRetryHttpClient client = new AutoRetryHttpClient(
new DefaultServiceUnavailableRetryStrategy(3, 3000));
HttpPost request = createRequest(tracker);
HttpHost httpHost = createHttpHost();
try {
HttpResponse resp = client.execute(httpHost, request);
int code = resp.getStatusLine().getStatusCode();
if (HttpResponseStatus.OK.code() == code) {
InputStream is = null;
try {
is = resp.getEntity().getContent();
is = new BufferedInputStream(is);
InputStreamReader reader = new InputStreamReader(is);
JsonStreamParser parser = new JsonStreamParser(
reader);
while (parser.hasNext()) {
JsonElement json = parser.next();
LOGGER.debug("Tracking data sent: " + json);
}
} finally {
if (is != null) {
is.close();
}
}
} else {
LOGGER.error(ERROR_FAILED_TO_SEND);
LOGGER.debug("Response code: " + code);
}
} catch (IOException e) {
LOGGER.warn(ERROR_FAILED_TO_SEND);
}
}
};
m_scheduledService.scheduleAtFixedRate(thread, 0, m_interval,
TimeUnit.SECONDS);
}