List of usage examples for com.fasterxml.jackson.core JsonParser getValueAsString
public String getValueAsString() throws IOException, JsonParseException
From source file:org.mayocat.jackson.OptionalStringListDeserializer.java
@Override public Optional<List<String>> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (jp.getCurrentToken().isScalarValue()) { // value is only one string return Optional.of(Arrays.asList(jp.getValueAsString())); } else {//from w w w.j a va 2 s. co m // Value is a list of strings List<String> result = Lists.newArrayList(); while (jp.nextToken().isScalarValue()) { String value = jp.getValueAsString(); result.add(value); } return Optional.of(result); } }
From source file:ch.rasc.wampspring.message.SubscribeMessage.java
public SubscribeMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.SUBSCRIBE); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/* w w w . j a v a2 s . co m*/ setTopicURI(replacePrefix(jp.getValueAsString(), wampSession)); }
From source file:ch.rasc.wampspring.message.WelcomeMessage.java
public WelcomeMessage(JsonParser jp) throws IOException { super(WampMessageType.WELCOME); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/*from w w w . ja v a 2 s.c o m*/ this.sessionId = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_NUMBER_INT) { throw new IOException(); } this.protocolVersion = jp.getValueAsInt(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.serverIdent = jp.getValueAsString(); }
From source file:ch.rasc.wampspring.message.UnsubscribeMessage.java
public UnsubscribeMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.UNSUBSCRIBE); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/*from ww w.j a v a 2s . co m*/ setTopicURI(replacePrefix(jp.getValueAsString(), wampSession)); }
From source file:ch.rasc.wampspring.message.CallErrorMessage.java
public CallErrorMessage(JsonParser jp) throws IOException { super(WampMessageType.CALLERROR); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }//w ww. j av a 2 s . c o m this.callID = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.errorURI = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.errorDesc = jp.getValueAsString(); if (jp.nextToken() != JsonToken.END_ARRAY) { this.errorDetails = jp.readValueAs(Object.class); } else { this.errorDetails = null; } }
From source file:ch.rasc.wampspring.message.EventMessage.java
public EventMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.EVENT); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }//from w w w . j a va 2s . c o m setTopicURI(replacePrefix(jp.getValueAsString(), wampSession)); jp.nextToken(); this.event = jp.readValueAs(Object.class); }
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(); }/* w w w .java 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; } }
From source file:org.apache.streams.twitter.converter.StreamsTwitterMapper.java
public StreamsTwitterMapper() { super();//w ww . j ava 2 s . c o m registerModule(new SimpleModule() { { addDeserializer(DateTime.class, new StdDeserializer<DateTime>(DateTime.class) { @Override public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException, JsonProcessingException { DateTime result = null; try { result = TWITTER_FORMATTER.parseDateTime(jpar.getValueAsString()); } catch (Exception e) { } try { result = RFC3339Utils.getInstance().parseToUTC(jpar.getValueAsString()); } catch (Exception e) { } return result; } }); } }); }
From source file:org.apache.streams.datasift.util.StreamsDatasiftMapper.java
public StreamsDatasiftMapper() { super();//w w w. j a v a 2 s . co m registerModule(new SimpleModule() { { addDeserializer(DateTime.class, new StdDeserializer<DateTime>(DateTime.class) { @Override public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException, JsonProcessingException { DateTime result = null; try { result = DATASIFT_FORMATTER.parseDateTime(jpar.getValueAsString()); } catch (Exception e) { } if (result == null) { try { result = RFC3339Utils.getInstance().parseToUTC(jpar.getValueAsString()); } catch (Exception e) { } } return result; } }); } }); }
From source file:com.netflix.discovery.converters.jackson.serializer.PortWrapperXmlDeserializer.java
@Override public InstanceInfo.PortWrapper deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { boolean enabled = false; int port = 0; while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("enabled".equals(fieldName)) { enabled = Boolean.valueOf(jp.getValueAsString()); } else if (fieldName == null || "".equals(fieldName)) { String value = jp.getValueAsString(); port = value == null ? 0 : Integer.parseInt(value); } else {//from w ww . ja va 2 s . c o m throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new InstanceInfo.PortWrapper(enabled, port); }