Java Code Examples for org.codehaus.jackson.JsonToken

The following are top voted examples for showing how to use org.codehaus.jackson.JsonToken. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: avro-json-decoder   File: ExtendedJsonDecoder.java   View source code 6 votes vote down vote up
@Override
public String readString() throws IOException {
	advance(Symbol.STRING);
	if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
		parser.advance(Symbol.MAP_KEY_MARKER);
		if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
			throw error("map-key");
		}
	} else {
		if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
			throw error("string");
		}
	}
	String result = in.getText();
	in.nextToken();
	return result;
}
 
Example 2
Project: avro-json-decoder   File: ExtendedJsonDecoder.java   View source code 6 votes vote down vote up
@Override
public int readEnum() throws IOException {
	advance(Symbol.ENUM);
	Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
	if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
		in.getText();
		int n = top.findLabel(in.getText());
		if (n >= 0) {
			in.nextToken();
			return n;
		}
		throw new AvroTypeException("Unknown symbol in enum " + in.getText());
	} else {
		throw error("fixed");
	}
}
 
Example 3
Project: avro-json-decoder   File: ExtendedJsonDecoder.java   View source code 6 votes vote down vote up
@Override
public int readIndex() throws IOException {
	advance(Symbol.UNION);
	Symbol.Alternative a = (Symbol.Alternative) parser.popSymbol();
	
	String label;
	if (in.getCurrentToken() == JsonToken.VALUE_NULL) {
		label = "null";
	} else if (in.getCurrentToken() == JsonToken.START_OBJECT &&
			in.nextToken() == JsonToken.FIELD_NAME) {
		label = in.getText();
		in.nextToken();
		parser.pushSymbol(Symbol.UNION_END);
	} else {
		throw error("start-union");
	}
	int n = a.findLabel(label);
	if (n < 0)
		throw new AvroTypeException("Unknown union branch " + label);
	parser.pushSymbol(a.getSymbol(n));
	return n;
}
 
Example 4
Project: personium-core   File: BarFileUtils.java   View source code 6 votes vote down vote up
/**
 * barファイルエントリからJSONファイルを読み込む.
 * @param <T> JSONMappedObject
 * @param inStream barファイルエントリのInputStream
 * @param entryName entryName
 * @param clazz clazz
 * @return JSONファイルから読み込んだオブジェクト
 * @throws IOException JSONファイル読み込みエラー
 */
public static <T> T readJsonEntry(
        InputStream inStream, String entryName, Class<T> clazz) throws IOException {
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    jp = f.createJsonParser(inStream);
    JsonToken token = jp.nextToken(); // JSONルート要素("{")
    Pattern formatPattern = Pattern.compile(".*/+(.*)");
    Matcher formatMatcher = formatPattern.matcher(entryName);
    String jsonName = formatMatcher.replaceAll("$1");
    T json = null;
    if (token == JsonToken.START_OBJECT) {
        try {
            json = mapper.readValue(jp, clazz);
        } catch (UnrecognizedPropertyException ex) {
            throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
        }
    } else {
        throw PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.params(jsonName);
    }
    return json;
}
 
Example 5
Project: personium-core   File: EventResource.java   View source code 6 votes vote down vote up
/**
 * リクエストボディを解析してEventオブジェクトを取得する.
 * @param reader Http入力ストリーム
 * @return 解析したEventオブジェクト
 */
protected JSONEvent getRequestBody(final Reader reader) {
    JSONEvent event = null;
    JsonParser jp = null;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory f = new JsonFactory();
    try {
        jp = f.createJsonParser(reader);
        JsonToken token = jp.nextToken(); // JSONルート要素("{")
        if (token == JsonToken.START_OBJECT) {
            event = mapper.readValue(jp, JSONEvent.class);
        } else {
            throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
        }
    } catch (IOException e) {
        throw PersoniumCoreException.Event.JSON_PARSE_ERROR;
    }
    return event;
}
 
Example 6
Project: opentsdb-flume   File: LegacyHttpSource.java   View source code 6 votes vote down vote up
public void parse(HttpRequest req) throws IOException {

      final JsonParser parser = jsonFactory.createJsonParser(
              new ChannelBufferInputStream(req.getContent()));

      parser.nextToken(); // Skip the wrapper

      while (parser.nextToken() != JsonToken.END_OBJECT) {

        final String metric = parser.getCurrentName();

        JsonToken currentToken = parser.nextToken();
        if (currentToken == JsonToken.START_OBJECT) {
          parseMetricObject(metric, parser);
        } else if (currentToken == JsonToken.START_ARRAY) {
          int illegalTokens = parseMetricArray(metric, parser);
          if(illegalTokens > 0) {
              logger.warn("{} illegal tokens encountered", illegalTokens);
          }
        } else {
          logger.warn("Illegal token: expected {} or {}, but was {}: {}",new Object[] {
                  JsonToken.START_OBJECT, JsonToken.START_ARRAY, currentToken, parser.getText()});
        }
      }
    }
 
Example 7
Project: opentsdb-flume   File: LegacyHttpSource.java   View source code 6 votes vote down vote up
private int parseMetricArray(String metric, JsonParser parser) throws IOException {
  JsonToken currentToken;
  int illegalTokens = 0;

  while ((currentToken = parser.nextToken()) != JsonToken.END_ARRAY) {

    if(!currentToken.equals(JsonToken.START_OBJECT)) {
        logger.warn("Illegal token: expected {}, but was {}: {}",
                new Object[] {JsonToken.START_OBJECT, currentToken, parser.getText()});
        illegalTokens++;
    } else {
        parseMetricObject(metric, parser);
    }

  }

  return illegalTokens;
}
 
Example 8
Project: es-hadoop-v2.2.0   File: BackportedJacksonMappingIterator.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected BackportedJacksonMappingIterator(JavaType type, JsonParser jp, DeserializationContext ctxt, JsonDeserializer<?> deser) {
    _type = type;
    _parser = jp;
    _context = ctxt;
    _deserializer = (JsonDeserializer<T>) deser;

    /* One more thing: if we are at START_ARRAY (but NOT root-level
     * one!), advance to next token (to allow matching END_ARRAY)
     */
    if (jp != null && jp.getCurrentToken() == JsonToken.START_ARRAY) {
        JsonStreamContext sc = jp.getParsingContext();
        // safest way to skip current token is to clear it (so we'll advance soon)
        if (!sc.inRoot()) {
            jp.clearCurrentToken();
        }
    }
}
 
Example 9
Project: es-hadoop-v2.2.0   File: BackportedJacksonMappingIterator.java   View source code 6 votes vote down vote up
/**
 * Equivalent of {@link #next} but one that may throw checked
 * exceptions from Jackson due to invalid input.
 */
public boolean hasNextValue() throws IOException {
    if (_parser == null) {
        return false;
    }
    JsonToken t = _parser.getCurrentToken();
    if (t == null) { // un-initialized or cleared; find next
        t = _parser.nextToken();
        // If EOF, no more
        if (t == null) {
            _parser.close();
            return false;
        }
        // And similarly if we hit END_ARRAY; except that we won't close parser
        if (t == JsonToken.END_ARRAY) {
            return false;
        }
    }
    return true;
}
 
Example 10
Project: playground   File: InstantDeserializer.java   View source code 6 votes vote down vote up
@Override
public Instant deserialize(final JsonParser parser, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException
{
    final JsonToken jsonToken = parser.getCurrentToken();

    if (jsonToken == JsonToken.VALUE_NUMBER_INT)
    {
        return new Instant(parser.getLongValue());
    }
    else if (jsonToken == JsonToken.VALUE_STRING)
    {
        final String str = parser.getText().trim();
        if (str.length() == 0)
        {
            return null;
        }
        final DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser();
        final DateTime dateTime = formatter.parseDateTime(str);

        return new Instant(dateTime.getMillis());
    }

    throw ctxt.mappingException(Instant.class);
}
 
Example 11
Project: hadoop-EAR   File: ClusterNode.java   View source code 6 votes vote down vote up
/**
 * Reads the list of grants from the JSON stream
 *  @param coronaSerializer The CoronaSerializer instance being used to read
 *                          the JSON from disk
 * @throws IOException
 */
private void readGrants(CoronaSerializer coronaSerializer)
  throws IOException {
  // Expecting the START_OBJECT token for grants
  coronaSerializer.readStartObjectToken("grants");
  JsonToken current = coronaSerializer.nextToken();
  while (current != JsonToken.END_OBJECT) {
    // We can access the key for the grant, but it is not required
    // Expecting the START_OBJECT token for the grant
    coronaSerializer.readStartObjectToken("grant");

    coronaSerializer.readField("grantId");
    GrantId grantId = new GrantId(coronaSerializer);
    coronaSerializer.readField("grant");
    ResourceRequestInfo resourceRequestInfo =
      new ResourceRequestInfo(coronaSerializer);

    // Expecting the END_OBJECT token for the grant
    coronaSerializer.readEndObjectToken("grant");

    // This will update the grants map and the resourceTypeToStatsMap map
    addGrant(grantId.getSessionId(), resourceRequestInfo);

    current = coronaSerializer.nextToken();
  }
}
 
Example 12
Project: hadoop-EAR   File: SessionManager.java   View source code 6 votes vote down vote up
/**
 * Reads back the sessions map from a JSON stream
 *
 * @param coronaSerializer The CoronaSerializer instance to be used to
 *                         read the JSON
 * @throws IOException
 */
private void readSessions(CoronaSerializer coronaSerializer)
  throws IOException {
  coronaSerializer.readField("sessions");
  // Expecting the START_OBJECT token for sessions
  coronaSerializer.readStartObjectToken("sessions");
  JsonToken current = coronaSerializer.nextToken();
  while (current != JsonToken.END_OBJECT) {
    String sessionId = coronaSerializer.getFieldName();
    Session session = new Session(clusterManager.conf.getCMHeartbeatDelayMax(),
      coronaSerializer);
    sessions.put(sessionId, session);
    current = coronaSerializer.nextToken();
  }
  // Done with reading the END_OBJECT token for sessions
}
 
Example 13
Project: hadoop-EAR   File: Session.java   View source code 6 votes vote down vote up
/**
 * Reads the idToGrant map from a JSON stream
 *
 * @param coronaSerializer The CoronaSerializer instance to be used to
 *                         read the JSON
 * @throws IOException
 */
private void readIdToGrant(CoronaSerializer coronaSerializer)
  throws IOException {
  coronaSerializer.readField("idToGrant");
  // Expecting the START_OBJECT token for idToGrant
  coronaSerializer.readStartObjectToken("idToGrant");
  JsonToken current = coronaSerializer.nextToken();
  while (current != JsonToken.END_OBJECT) {
    Integer id = Integer.parseInt(coronaSerializer.getFieldName());
    ResourceGrant resourceGrant =
      coronaSerializer.readValueAs(ResourceGrant.class);
    idToGrant.put(id, new ResourceGrant(resourceGrant));
    current = coronaSerializer.nextToken();
  }
  // Done with reading the END_OBJECT token for idToGrant
}
 
Example 14
Project: hadoop-EAR   File: Session.java   View source code 6 votes vote down vote up
/**
 * Reads the typeToFirstWait map from the JSON stream
 *
 * @param coronaSerializer The CoronaSerializer instance to be used to
 *                         read the JSON
 * @throws IOException
 */
private void readTypeToFirstWait(CoronaSerializer coronaSerializer)
  throws IOException {
  coronaSerializer.readField("typeToFirstWait");
  // Expecting the START_OBJECT token for typeToFirstWait
  coronaSerializer.readStartObjectToken("typeToFirstWait");
  JsonToken current = coronaSerializer.nextToken();
  while (current != JsonToken.END_OBJECT) {
    String resourceTypeStr = coronaSerializer.getFieldName();
    Long wait = coronaSerializer.readValueAs(Long.class);
    current = coronaSerializer.nextToken();
    if (wait == -1) {
      wait = null;
    }
    typeToFirstWait.put(ResourceType.valueOf(resourceTypeStr), wait);
  }
  // Done with reading the END_OBJECT token for typeToFirstWait
}
 
Example 15
Project: hadoop-EAR   File: NodeManager.java   View source code 6 votes vote down vote up
/**
 * Reads the nameToNode map from the JSON stream
 * @param coronaSerializer The CoronaSerializer instance to be used to
 *                         read the JSON
 * @throws IOException
 */
private void readNameToNode(CoronaSerializer coronaSerializer)
  throws IOException {
  coronaSerializer.readField("nameToNode");
  // Expecting the START_OBJECT token for nameToNode
  coronaSerializer.readStartObjectToken("nameToNode");
  JsonToken current = coronaSerializer.nextToken();
  while (current != JsonToken.END_OBJECT) {
    // nodeName is the key, and the ClusterNode is the value here
    String nodeName = coronaSerializer.getFieldName();
    ClusterNode clusterNode = new ClusterNode(coronaSerializer);
    if (!nameToNode.containsKey(nodeName)) {
      nameToNode.put(nodeName, clusterNode);
    }
    current = coronaSerializer.nextToken();
  }
  // Done with reading the END_OBJECT token for nameToNode
}
 
Example 16
Project: hadoop-EAR   File: NodeManager.java   View source code 6 votes vote down vote up
/**
 * Reads the nameToApps map from the JSON stream
 * @param coronaSerializer The CoronaSerializer instance to be used to
 *                         read the JSON
 * @throws IOException
 */
private void readNameToApps(CoronaSerializer coronaSerializer)
  throws IOException {
  coronaSerializer.readField("nameToApps");
  // Expecting the START_OBJECT token for nameToApps
  coronaSerializer.readStartObjectToken("nameToApps");
  JsonToken current = coronaSerializer.nextToken();

  while (current != JsonToken.END_OBJECT) {
    String nodeName = coronaSerializer.getFieldName();
    // Expecting the START_OBJECT token for the Apps
    coronaSerializer.readStartObjectToken(nodeName);
    Map<String, String> appMap = coronaSerializer.readValueAs(Map.class);
    Map<ResourceType, String> appsOnNode =
      new HashMap<ResourceType, String>();

    for (Map.Entry<String, String> entry : appMap.entrySet()) {
      appsOnNode.put(ResourceType.valueOf(entry.getKey()),
        entry.getValue());
    }

    nameToApps.put(nodeName, appsOnNode);
    current = coronaSerializer.nextToken();
  }
}
 
Example 17
Project: majordodo   File: BrokerStatusSnapshot.java   View source code 6 votes vote down vote up
private static SlotStatus readSlotStatus(JsonParser jParser) throws IOException {
    SlotStatus res = new SlotStatus();

    while (jParser.nextToken() != JsonToken.END_OBJECT) {
        switch (jParser.getCurrentName() + "") {
            case "slotId":
                nextToken(jParser);
                res.setSlot(readValue(jParser));
                break;
            default:
                throw new IOException("Unexpected field " + jParser.getCurrentName());
        }
    }

    return res;
}
 
Example 18
Project: Rosetta.NetAppStoragePlugin   File: CDMIConnector.java   View source code 6 votes vote down vote up
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
Example 19
Project: ODFExplorer   File: StyleJSONReader.java   View source code 6 votes vote down vote up
private static void findDiffProp(JsonParser jParser) throws JsonParseException, IOException {
		String propName = null;
		String val1 = null;
		String val2 = null;
		while (jParser.nextToken() != JsonToken.END_ARRAY) {

			String fieldname = jParser.getCurrentName();
			if ("name".equals(fieldname)) {
//				System.out.println("iterating children");
				jParser.nextToken(); 
				propName = jParser.getText();
			}
			if ("value1".equals(fieldname)) {
//				System.out.println("Diff property");
				jParser.nextToken(); 
				val1 = jParser.getText();
			}
			if ("value2".equals(fieldname)) {
				jParser.nextToken(); 
				val2 = jParser.getText();
				System.out.println("Diff " + propName + " " + val1 + " -> " + val2);
				propDiffCount++;
			}
		}
		
	}
 
Example 20
Project: appverse-server   File: CustomMappingJacksonHttpMessageConverter.java   View source code 6 votes vote down vote up
protected Object[] readInternal(Class<?>[] parameterTypes, String payload) throws Exception {
	JsonFactory jsonFactory = this.objectMapper.getJsonFactory();
	JsonParser jp = jsonFactory.createJsonParser(payload);
	JsonToken token;
	List<Object> lObjs = new ArrayList<Object>();
	int i=0;
	while ((token = jp.nextToken()) != null) {
	    switch (token) {
	    	case VALUE_NUMBER_INT:
               case VALUE_STRING:
	        case START_OBJECT:
	        	Object obj = jp.readValueAs(parameterTypes[i]);
	        	lObjs.add(obj);
			    i++;
	            break;
		default:
			break;
	    }
	}
	if( lObjs.size() != parameterTypes.length) {
		throw new Exception("Parsed parameters do not match requested types.");
	}
	Object [] parametersFound = lObjs.toArray();
	return parametersFound;
}
 
Example 21
Project: Rosetta.dps-sdk-projects   File: CDMIConnector.java   View source code 6 votes vote down vote up
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
Example 22
Project: Rosetta.dps-sdk-projects   File: CDMIConnector.java   View source code 6 votes vote down vote up
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
Example 23
Project: Rosetta.dps-sdk-projects   File: CDMIConnector.java   View source code 6 votes vote down vote up
private String getSpecificJSONValue(HttpResponse response, String jsonKey) throws JsonParseException, IllegalStateException, IOException {
	InputStream content = response.getEntity().getContent();
	if (isSuccessfulResponse(response)) {
		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(content);
		while ((jp.nextToken()) != JsonToken.END_OBJECT) {
			if (jsonKey.equals(jp.getCurrentName())) {
				jp.nextToken();
				return jp.getText();
			}
		}
	} else {
		String string = IOUtils.toString(content);
		System.err.println(string);
	}
	return null;
}
 
Example 24
Project: iis   File: HackedJsonDecoder.java   View source code 6 votes vote down vote up
@Override
public String readString() throws IOException {
  advance(Symbol.STRING);
  if (parser.topSymbol() == Symbol.MAP_KEY_MARKER) {
    parser.advance(Symbol.MAP_KEY_MARKER);
    if (in.getCurrentToken() != JsonToken.FIELD_NAME) {
      throw error("map-key");
    }
  } else {
    if (in.getCurrentToken() != JsonToken.VALUE_STRING) {
      throw error("string");
    }
  }
  String result = in.getText();
  in.nextToken();
  return result;
}
 
Example 25
Project: iis   File: HackedJsonDecoder.java   View source code 6 votes vote down vote up
@Override
public int readEnum() throws IOException {
  advance(Symbol.ENUM);
  Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
  if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
    in.getText();
    int n = top.findLabel(in.getText());
    if (n >= 0) {
      in.nextToken();
      return n;
    }
    throw new AvroTypeException("Unknown symbol in enum " + in.getText());
  } else {
    throw error("fixed");
  }
}
 
Example 26
Project: community-edition-old   File: NodeRefDeserializer.java   View source code 6 votes vote down vote up
@Override
public NodeRef deserialize(JsonParser jp, DeserializationContext ctxt)
		throws IOException, JsonProcessingException
{
       JsonToken curr = jp.getCurrentToken();

       if (curr == JsonToken.VALUE_STRING)
       {
           String nodeRefString = jp.getText();
           NodeRef nodeRef = getNodeRef(nodeRefString);
           return nodeRef;
       }
       else
       {
       	throw new IOException("Unable to deserialize nodeRef: " + curr.asString());
       }
}
 
Example 27
Project: 12306-android-Decompile   File: ReaderBasedParser.java   View source code 6 votes vote down vote up
protected void _matchToken(JsonToken paramJsonToken)
  throws IOException, JsonParseException
{
  String str = paramJsonToken.asString();
  int i = 1;
  int j = str.length();
  while (i < j)
  {
    if ((this._inputPtr >= this._inputEnd) && (!loadMore()))
      _reportInvalidEOF(" in a value");
    if (this._inputBuffer[this._inputPtr] != str.charAt(i))
      _reportInvalidToken(str.substring(0, i), "'null', 'true' or 'false'");
    this._inputPtr = (1 + this._inputPtr);
    i++;
  }
}
 
Example 28
Project: Aeron   File: MetadataValueDeserializer.java   View source code 6 votes vote down vote up
private Object getPEPCredentials(JsonParser jp) throws JsonParseException,
		IOException {
	JsonToken token = jp.getCurrentToken();

	PEPCredentials result = new PEPCredentials();

	while (!token.equals(JsonToken.END_OBJECT)) {
		token = jp.nextToken();
		if (jp.getCurrentName().equalsIgnoreCase("username")) {
			result.setUsername(jp.getText());
		} else if (jp.getCurrentName().equalsIgnoreCase("password")) {
			result.setPassword(jp.getText());
		} else {
			throw new JsonParseException(
					"unknown field for pepcredentials", null);
		}
		token = jp.nextToken();
	}
	return result;
}
 
Example 29
Project: Aeron   File: MetadataValueDeserializer.java   View source code 6 votes vote down vote up
private Object getAsJsonString(JsonParser jp) throws JsonParseException,
		IOException {
	String asString = "";
	JsonToken token = jp.getCurrentToken();

	while (!token.equals(JsonToken.END_OBJECT)) {

		String key = jp.getText();
		token = jp.nextToken();
		String value = jp.getText();
		String.format("\"%s\" : \"%s\"", key, value);

		if (asString.isEmpty()) {
			asString += String.format("\"%s\" : \"%s\"", key, value);
		} else {
			asString += String.format(", \"%s\" : \"%s\"", key, value);
		}
		token = jp.nextToken();
	}
	asString = String.format("{%s}", asString);
	return asString;
}
 
Example 30
Project: 12306-android-Decompile   File: MapDeserializer.java   View source code 6 votes vote down vote up
public Map<Object, Object> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
  throws IOException, JsonProcessingException
{
  JsonToken localJsonToken = paramJsonParser.getCurrentToken();
  if ((localJsonToken != JsonToken.START_OBJECT) && (localJsonToken != JsonToken.FIELD_NAME) && (localJsonToken != JsonToken.END_OBJECT))
    throw paramDeserializationContext.mappingException(getMapClass());
  if (this._propertyBasedCreator != null)
    return _deserializeUsingCreator(paramJsonParser, paramDeserializationContext);
  if (this._defaultCtor == null)
    throw paramDeserializationContext.instantiationException(getMapClass(), "No default constructor found");
  try
  {
    Map localMap = (Map)this._defaultCtor.newInstance(new Object[0]);
    _readAndBind(paramJsonParser, paramDeserializationContext, localMap);
    return localMap;
  }
  catch (Exception localException)
  {
  }
  throw paramDeserializationContext.instantiationException(getMapClass(), localException);
}
 
Example 31
Project: 12306-android-Decompile   File: EnumSetDeserializer.java   View source code 6 votes vote down vote up
public EnumSet<?> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
  throws IOException, JsonProcessingException
{
  if (!paramJsonParser.isExpectedStartArrayToken())
    throw paramDeserializationContext.mappingException(EnumSet.class);
  EnumSet localEnumSet = constructSet();
  while (true)
  {
    JsonToken localJsonToken = paramJsonParser.nextToken();
    if (localJsonToken == JsonToken.END_ARRAY)
      break;
    if (localJsonToken == JsonToken.VALUE_NULL)
      throw paramDeserializationContext.mappingException(this._enumClass);
    localEnumSet.add(this._enumDeserializer.deserialize(paramJsonParser, paramDeserializationContext));
  }
  return localEnumSet;
}
 
Example 32
Project: 12306-android-Decompile   File: NodeCursor.java   View source code 6 votes vote down vote up
public JsonToken nextToken()
{
  if (this._needEntry)
  {
    if (!this._contents.hasNext())
    {
      this._current = null;
      return null;
    }
    this._needEntry = false;
    this._current = ((Map.Entry)this._contents.next());
    return JsonToken.FIELD_NAME;
  }
  this._needEntry = true;
  return ((JsonNode)this._current.getValue()).asToken();
}
 
Example 33
Project: spring-open   File: IPv4Deserializer.java   View source code 6 votes vote down vote up
@Override
public IPv4 deserialize(JsonParser jp,
                        DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    IPv4 ipv4 = null;

    jp.nextToken();        // Move to JsonToken.START_OBJECT
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = jp.getCurrentName();
        if ("value".equals(fieldname)) {
            String value = jp.getText();
            log.debug("Fieldname: {} Value: {}", fieldname, value);
            ipv4 = new IPv4(value);
        }
    }
    return ipv4;
}
 
Example 34
Project: 12306-android-Decompile   File: Utf8StreamParser.java   View source code 6 votes vote down vote up
protected void _matchToken(JsonToken paramJsonToken)
  throws IOException, JsonParseException
{
  byte[] arrayOfByte = paramJsonToken.asByteArray();
  int i = 1;
  int j = arrayOfByte.length;
  while (i < j)
  {
    if (this._inputPtr >= this._inputEnd)
      loadMoreGuaranteed();
    if (arrayOfByte[i] != this._inputBuffer[this._inputPtr])
      _reportInvalidToken(paramJsonToken.asString().substring(0, i), "'null', 'true' or 'false'");
    this._inputPtr = (1 + this._inputPtr);
    i++;
  }
}
 
Example 35
Project: 12306-android-Decompile   File: CollectionDeserializer.java   View source code 6 votes vote down vote up
private final Collection<Object> handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<Object> paramCollection)
  throws IOException, JsonProcessingException
{
  if (!paramDeserializationContext.isEnabled(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
    throw paramDeserializationContext.mappingException(this._collectionType.getRawClass());
  JsonDeserializer localJsonDeserializer = this._valueDeserializer;
  TypeDeserializer localTypeDeserializer = this._valueTypeDeserializer;
  Object localObject;
  if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_NULL)
    localObject = null;
  while (true)
  {
    paramCollection.add(localObject);
    return paramCollection;
    if (localTypeDeserializer == null)
    {
      localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
      continue;
    }
    localObject = localJsonDeserializer.deserializeWithType(paramJsonParser, paramDeserializationContext, localTypeDeserializer);
  }
}
 
Example 36
Project: 12306-android-Decompile   File: EnumMapDeserializer.java   View source code 6 votes vote down vote up
public EnumMap<?, ?> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
  throws IOException, JsonProcessingException
{
  if (paramJsonParser.getCurrentToken() != JsonToken.START_OBJECT)
    throw paramDeserializationContext.mappingException(EnumMap.class);
  EnumMap localEnumMap = constructMap();
  if (paramJsonParser.nextToken() != JsonToken.END_OBJECT)
  {
    String str = paramJsonParser.getCurrentName();
    Enum localEnum = this._enumResolver.findEnum(str);
    if (localEnum == null)
      throw paramDeserializationContext.weirdStringException(this._enumResolver.getEnumClass(), "value not one of declared Enum instance names");
    if (paramJsonParser.nextToken() == JsonToken.VALUE_NULL);
    for (Object localObject = null; ; localObject = this._valueDeserializer.deserialize(paramJsonParser, paramDeserializationContext))
    {
      localEnumMap.put(localEnum, localObject);
      break;
    }
  }
  return localEnumMap;
}
 
Example 37
Project: 12306-android-Decompile   File: SettableBeanProperty.java   View source code 6 votes vote down vote up
public final void deserializeAndSet(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Object paramObject)
  throws IOException, JsonProcessingException
{
  if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_NULL)
    return;
  Object localObject;
  try
  {
    localObject = this._getter.invoke(paramObject, new Object[0]);
    if (localObject == null)
      throw new JsonMappingException("Problem deserializing 'setterless' property '" + getName() + "': get method returned null");
  }
  catch (Exception localException)
  {
    _throwAsIOE(localException);
    return;
  }
  this._valueDeserializer.deserialize(paramJsonParser, paramDeserializationContext, localObject);
}
 
Example 38
Project: 12306-android-Decompile   File: ReaderBasedParser.java   View source code 6 votes vote down vote up
public byte[] getBinaryValue(Base64Variant paramBase64Variant)
  throws IOException, JsonParseException
{
  if ((this._currToken != JsonToken.VALUE_STRING) && ((this._currToken != JsonToken.VALUE_EMBEDDED_OBJECT) || (this._binaryValue == null)))
    _reportError("Current token (" + this._currToken + ") not VALUE_STRING or VALUE_EMBEDDED_OBJECT, can not access as binary");
  if (this._tokenIncomplete);
  try
  {
    this._binaryValue = _decodeBase64(paramBase64Variant);
    this._tokenIncomplete = false;
    return this._binaryValue;
  }
  catch (IllegalArgumentException localIllegalArgumentException)
  {
  }
  throw _constructError("Failed to decode VALUE_STRING as base64 (" + paramBase64Variant + "): " + localIllegalArgumentException.getMessage());
}
 
Example 39
Project: 12306-android-Decompile   File: EnumDeserializer.java   View source code 6 votes vote down vote up
public Object deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
  throws IOException, JsonProcessingException
{
  if (paramJsonParser.getCurrentToken() != JsonToken.VALUE_STRING)
    throw paramDeserializationContext.mappingException(this._enumClass);
  String str = paramJsonParser.getText();
  try
  {
    Object localObject = this._factory.invoke(this._enumClass, new Object[] { str });
    return localObject;
  }
  catch (Exception localException)
  {
    ClassUtil.unwrapAndThrowAsIAE(localException);
  }
  return null;
}
 
Example 40
Project: 12306-android-Decompile   File: StringCollectionDeserializer.java   View source code 6 votes vote down vote up
private Collection<String> deserializeUsingCustom(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<String> paramCollection)
  throws IOException, JsonProcessingException
{
  JsonDeserializer localJsonDeserializer = this._valueDeserializer;
  JsonToken localJsonToken = paramJsonParser.nextToken();
  if (localJsonToken != JsonToken.END_ARRAY)
  {
    if (localJsonToken == JsonToken.VALUE_NULL);
    for (Object localObject = null; ; localObject = (String)localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext))
    {
      paramCollection.add(localObject);
      break;
    }
  }
  return (Collection<String>)paramCollection;
}