List of usage examples for com.fasterxml.jackson.core JsonToken END_ARRAY
JsonToken END_ARRAY
To view the source code for com.fasterxml.jackson.core JsonToken END_ARRAY.
Click Source Link
From source file:com.github.heuermh.ensemblrestclient.JacksonOverlapConverter.java
static List<Variation> parseOverlap(final JsonFactory jsonFactory, final InputStream inputStream) throws IOException { JsonParser parser = null;//ww w . j a va2 s.c o m try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String reference = null; List<String> alternateAlleles = new ArrayList<String>(); String locationName = null; String coordinateSystem = "chromosome"; int start = -1; int end = -1; int strand = -1; List<Variation> variationFeatures = new ArrayList<Variation>(); while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("seq_region_name".equals(field)) { locationName = parser.getText(); } else if ("start".equals(field)) { start = Integer.parseInt(parser.getText()); } else if ("end".equals(field)) { end = Integer.parseInt(parser.getText()); } else if ("strand".equals(field)) { strand = Integer.parseInt(parser.getText()); } else if ("alt_alleles".equals(field)) { int index = 0; while (parser.nextToken() != JsonToken.END_ARRAY) { if (index == 0) { reference = parser.getText(); } else if (index == 1) { alternateAlleles.add(parser.getText()); } index++; } } } variationFeatures.add(new Variation(id, reference, alternateAlleles, new Location(locationName, coordinateSystem, start, end, strand))); id = null; reference = null; alternateAlleles.clear(); locationName = null; start = -1; end = -1; strand = -1; } return variationFeatures; } finally { try { inputStream.close(); } catch (Exception e) { // ignored } try { parser.close(); } catch (Exception e) { // ignored } } }
From source file:org.apache.batchee.jackson.JacksonJsonReader.java
@Override public void open(final Serializable checkpoint) throws Exception { super.open(checkpoint); final ObjectMapper mapper = Jacksons.newMapper(configuration); parser = mapper.getFactory().createParser(new File(file)); if (type != null) { clazz = Thread.currentThread().getContextClassLoader().loadClass(type); } else {// ww w . j av a 2 s. com clazz = null; } if (skipRoot == null || "true".equalsIgnoreCase(skipRoot)) { final JsonToken token = parser.nextToken(); if (token == JsonToken.START_ARRAY) { end = JsonToken.END_ARRAY; } else { end = JsonToken.END_OBJECT; } } }
From source file:org.tanrabad.survey.service.json.MultiPolygonTypeConverter.java
private List<Location> getChildPolygon(JsonParser jsonParser) throws IOException { List<Location> eachChildPolygon; if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) { eachChildPolygon = new ArrayList<>(); while (jsonParser.nextToken() != JsonToken.END_ARRAY) { eachChildPolygon.add(getLocation(jsonParser)); }//from w w w.j a va2 s. c om } else { eachChildPolygon = null; } return eachChildPolygon; }
From source file:org.dbrain.data.jackson.serializers.JacksonSerializationUtils.java
public static Value parseValue(JsonParser parser, DeserializationContext ctxt) throws IOException { JsonToken token = getToken(parser);//from ww w .java 2 s. c o m if (token != null) { Value result; switch (token) { case VALUE_STRING: result = Value.of(parser.getValueAsString()); break; case VALUE_NUMBER_FLOAT: result = Value.of(parser.getDoubleValue()); break; case VALUE_NUMBER_INT: result = Value.of(parser.getBigIntegerValue()); break; case VALUE_NULL: result = NullValueImpl.NULL; break; case VALUE_TRUE: result = Value.of(Boolean.TRUE); break; case VALUE_FALSE: result = Value.of(Boolean.FALSE); break; case START_OBJECT: { ValueMap values = ValueMap.newInstance(); while (parser.nextToken() == JsonToken.FIELD_NAME) { String key = parser.getCurrentName(); parser.nextToken(); Value v = parseValue(parser, ctxt); if (v == null) { throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } values.put(key, v); } if (getToken(parser) == JsonToken.END_OBJECT) { parser.clearCurrentToken(); } else { throw ctxt.wrongTokenException(parser, JsonToken.END_OBJECT, null); } result = values; } break; case START_ARRAY: { ValueList values = ValueList.newInstance(); while (parser.nextToken() != JsonToken.END_ARRAY) { Value v = parseValue(parser, ctxt); if (v == null) { throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } values.add(v); } if (getToken(parser) == JsonToken.END_ARRAY) { parser.clearCurrentToken(); } else { throw ctxt.wrongTokenException(parser, JsonToken.END_ARRAY, null); } result = values; } break; default: throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } return result; } else { return null; } }
From source file:com.basistech.AfterburnerOopsTest.java
@Test public void oops() throws Exception { SmileFactory smileFactory = new SmileFactory(); ObjectMapper mapper = new ObjectMapper(smileFactory); mapper = AnnotatedDataModelModule.setupObjectMapper(mapper); EntityMention em = new EntityMention(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); List<EntityMention> mentions = Lists.newArrayList(); mentions.add(em);//from www. java 2 s . c om mapper.writeValue(byteArrayOutputStream, mentions); mapper = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper(smileFactory)); mapper.registerModule(new AfterburnerModule()); JsonParser jp = smileFactory.createParser(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); jp.setCodec(mapper); JsonToken current; current = jp.nextToken(); if (current != JsonToken.START_ARRAY) { System.err.println("Error: root should be array: quiting."); return; } while (jp.nextToken() != JsonToken.END_ARRAY) { jp.readValueAs(EntityMention.class); } }
From source file:org.apache.nifi.minifi.c2.provider.nifi.rest.TemplatesIterator.java
private Pair<String, String> getNext() throws IOException { while (parser.nextToken() != JsonToken.END_ARRAY) { if ("template".equals(parser.getCurrentName())) { String id = null;//from ww w . j av a2 s . c om String name = null; while (parser.nextToken() != JsonToken.END_OBJECT) { String currentName = parser.getCurrentName(); if ("id".equals(currentName)) { parser.nextToken(); id = parser.getText(); } else if ("name".equals(currentName)) { parser.nextToken(); name = parser.getText(); } } return new Pair<>(id, name); } } return null; }
From source file:org.onosproject.north.aaa.api.parser.impl.ScopeParser.java
@Override public Set<Scope> parseJson(InputStream stream) throws IOException, ParseException { // begin parsing JSON to Application class ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree(stream); JsonParser jp = jsonNode.traverse(); Set<Scope> scopeSet = new HashSet<>(); // continue parsing the token till the end of input is reached while (!jp.isClosed()) { // get the token JsonToken token = jp.nextToken(); // if its the last token then we are done if (token == null) { break; }//from ww w .j ava 2 s. c o m if (JsonToken.FIELD_NAME.equals(token) && "scopes".equals(jp.getCurrentName())) { token = jp.nextToken(); if (!JsonToken.START_ARRAY.equals(token)) { // bail out throw new ParseException("expected ARRAY after scopes"); } while (true) { token = jp.nextToken(); if (JsonToken.END_ARRAY.equals(token)) { // bail out break; } if (JsonToken.START_OBJECT.equals(token)) { Scope scope = jsonToScope(jp); scopeSet.add(scope); } } } } return scopeSet; }
From source file:org.onosproject.north.aaa.api.parser.impl.ApplicationParser.java
@Override public Set<Application> parseJson(InputStream stream) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree(stream); JsonParser jp = jsonNode.traverse(); Set<Application> applicationSet = new HashSet<>(); // continue parsing the token till the end of input is reached while (!jp.isClosed()) { // get the token JsonToken token = jp.nextToken(); // if its the last token then we are done if (token == null) { break; }//from ww w. j a va 2 s .co m if (JsonToken.FIELD_NAME.equals(token) && "applications".equals(jp.getCurrentName())) { token = jp.nextToken(); if (!JsonToken.START_ARRAY.equals(token)) { // bail out throw new ParseException("expected ARRAY after applications"); } while (true) { token = jp.nextToken(); if (JsonToken.END_ARRAY.equals(token)) { // bail out break; } if (JsonToken.START_OBJECT.equals(token)) { Application app = jsonToApplication(jp); applicationSet.add(app); } } } } return applicationSet; }
From source file:com.netflix.aegisthus.tools.AegisthusSerializer.java
public Map<String, Object> deserialize(String data) throws IOException { try {/* w ww.j a v a2s.com*/ Map<String, Object> map = new LinkedHashMap<String, Object>(); JsonParser jp = jsonFactory.createJsonParser(data); jp.nextToken(); // Object jp.nextToken(); // key map.put(KEY, new DataByteArray(jp.getCurrentName().getBytes())); jp.nextToken(); // object while (jp.nextToken() != JsonToken.END_OBJECT) { String field = jp.getCurrentName(); if (DELETEDAT.equals(field.toUpperCase())) { jp.nextToken(); map.put(DELETEDAT, jp.getLongValue()); } else { jp.nextToken(); while (jp.nextToken() != JsonToken.END_ARRAY) { List<Object> cols = new ArrayList<Object>(); jp.nextToken(); String name = jp.getText(); cols.add(name); jp.nextToken(); cols.add(new DataByteArray(jp.getText().getBytes())); jp.nextToken(); cols.add(jp.getLongValue()); if (jp.nextToken() != JsonToken.END_ARRAY) { String status = jp.getText(); cols.add(status); if ("e".equals(status)) { jp.nextToken(); cols.add(jp.getLongValue()); jp.nextToken(); cols.add(jp.getLongValue()); } else if ("c".equals(status)) { jp.nextToken(); cols.add(jp.getLongValue()); } jp.nextToken(); } map.put(name, cols); } } } return map; } catch (IOException e) { LOG.error(data); throw e; } }
From source file:ch.rasc.wampspring.message.CallMessage.java
public CallMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.CALL); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/*from w w w. j av a 2s.c o m*/ this.callID = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.procURI = replacePrefix(jp.getValueAsString(), wampSession); List<Object> args = new ArrayList<>(); while (jp.nextToken() != JsonToken.END_ARRAY) { args.add(jp.readValueAs(Object.class)); } if (!args.isEmpty()) { this.arguments = Collections.unmodifiableList(args); } else { this.arguments = null; } }