当前位置: 首页>>代码示例>>Java>>正文


Java DeserializationContext类代码示例

本文整理汇总了Java中org.codehaus.jackson.map.DeserializationContext的典型用法代码示例。如果您正苦于以下问题:Java DeserializationContext类的具体用法?Java DeserializationContext怎么用?Java DeserializationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DeserializationContext类属于org.codehaus.jackson.map包,在下文中一共展示了DeserializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Directive deserialize(JsonParser jp, DeserializationContext ctx)
        throws IOException {
    ObjectReader reader = ObjectMapperUtil.instance().getObjectReader();
    ObjectNode obj = (ObjectNode) reader.readTree(jp);
    Iterator<Map.Entry<String, JsonNode>> elementsIterator = obj.getFields();

    String rawMessage = obj.toString();
    DialogRequestIdHeader header = null;
    JsonNode payloadNode = null;
    ObjectReader headerReader =
            ObjectMapperUtil.instance().getObjectReader(DialogRequestIdHeader.class);
    while (elementsIterator.hasNext()) {
        Map.Entry<String, JsonNode> element = elementsIterator.next();
        if (element.getKey().equals("header")) {
            header = headerReader.readValue(element.getValue());
        }
        if (element.getKey().equals("payload")) {
            payloadNode = element.getValue();
        }
    }
    if (header == null) {
        throw ctx.mappingException("Missing header");
    }
    if (payloadNode == null) {
        throw ctx.mappingException("Missing payload");
    }

    return createDirective(header, payloadNode, rawMessage);
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:31,代码来源:Directive.java

示例2: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Window deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    Double value = node.get("value").asDouble();
    Window window = new Window(value);
    
    if (node.has("bounds")) {
        long lowerBound = node.get("bounds").get(0).asLong();
        long upperBound = node.get("bounds").get(1).asLong();
        
        window.withLowerBound(lowerBound).withUpperBound(upperBound);
    }

    return window;
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:17,代码来源:WindowDeserializer.java

示例3: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public StatePair deserialize(JsonParser parser, 
                             DeserializationContext context)
throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper) parser.getCodec();
  // set the state-pair object tree
  ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
  Class<?> stateClass = null;
  
  try {
    stateClass = 
      Class.forName(statePairObject.get("className").getTextValue().trim());
  } catch (ClassNotFoundException cnfe) {
    throw new RuntimeException("Invalid classname!", cnfe);
  }
  
  String stateJsonString = statePairObject.get("state").toString();
  State state = (State) mapper.readValue(stateJsonString, stateClass);
  
  return new StatePair(state);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:StateDeserializer.java

示例4: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public ProducedEventsResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    if (node.isArray()) {
        List<ProducedEventResult> responses = new ArrayList<>();
        Iterator<JsonNode> it = node.iterator();
        
        while (it.hasNext()) {
            JsonNode n = it.next();
            responses.add(new ProducedEventResult(n.get("created").asBoolean()));
        }
        
        return new ProducedEventsResult(responses);
    } else {
        String reason = node.get("reason").asText();
        return new ProducedEventsResult(reason);
    }
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:20,代码来源:ProducedEventsResponseDeserializer.java

示例5: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public TopicRecord deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    
    String topic = node.get("topic").asText();
    long partition = node.get("partition").asLong();
    long offset = node.get("offset").asLong();
    long timestamp = node.get("timestamp").asLong();
    
    String key = null;
    if (node.has("key")) {
        key = node.get("key").asText();
    }
    
    Map<Object, Object> value = new ObjectMapper().readValue(node.get("value").toString(), Map.class);
    return new TopicRecord(topic, key, partition, offset, timestamp, value);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:18,代码来源:TopicRecordDeserializer.java

示例6: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public SubscribeToTopicResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
    JsonNode node = jp.getCodec().readTree(jp);
    boolean success = false;
    String reason = null;
    
    if (node.has("subscribed")) {
        success = node.get("subscribed").asBoolean();
    }
    
    if (node.has("reason")) {
        reason = node.get("reason").asText();
    }

    return new SubscribeToTopicResult(success, reason);
}
 
开发者ID:PyroclastIO,项目名称:pyroclast-java,代码行数:17,代码来源:SubscribeToTopicResponseDeserializer.java

示例7: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public JsonUpdateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode node = obj.readTree(jp).get(0);

    final Set<String> groupIds = deserializeGroupIdentifiers(node);
    return new JsonUpdateWebServer(node.get("webserverId").getValueAsText(),
                                   node.get("webserverName").getTextValue(),
                                   node.get("hostName").getTextValue(),
                                   node.get("portNumber").getValueAsText(),
                                   node.get("httpsPort").getValueAsText(),
                                   groupIds,
                                   node.get("statusPath").getTextValue(),
                                   node.get("apacheHttpdMediaId").getTextValue());
}
 
开发者ID:cerner,项目名称:jwala,代码行数:18,代码来源:JsonUpdateWebServer.java

示例8: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public JsonCreateWebServer deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode node = obj.readTree(jp).get(0);

    final JsonNode apacheHttpdMediaId = node.get("apacheHttpdMediaId");
    final JsonCreateWebServer jcws = new JsonCreateWebServer(node.get("webserverName").getTextValue(),
            node.get("hostName").getTextValue(),
            node.get("portNumber").asText(),
            node.get("httpsPort").asText(),
               deserializeGroupIdentifiers(node),
            node.get("statusPath").getTextValue(),
            apacheHttpdMediaId == null ? null : apacheHttpdMediaId.asText());
    return jcws;
}
 
开发者ID:cerner,项目名称:jwala,代码行数:18,代码来源:JsonCreateWebServer.java

示例9: BackportedJacksonMappingIterator

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@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();
        }
    }
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:19,代码来源:BackportedJacksonMappingIterator.java

示例10: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@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);
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:26,代码来源:InstantDeserializer.java

示例11: addDiscoverableDeserializers

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
/**
 * Search for any registered JsonDeserialize instances that have been declared using the
 * ServiceLoader. Add any found to the given mapper in a 'magic' module.
 */
private static void addDiscoverableDeserializers(final ObjectMapper mapper) {

    final ServiceLoader<JsonDeserializer> loader = ServiceLoader.load(JsonDeserializer.class);
    final Iterator<JsonDeserializer> iterator = loader.iterator();
    final SimpleModule magic = new SimpleModule("magic", new Version(1, 0, 0, ""));

    while (iterator.hasNext()) {

        final JsonDeserializer<?> deserializer = iterator.next();

        try {
            final Method deserialeMethod = deserializer.getClass()
                    .getDeclaredMethod("deserialize", JsonParser.class, DeserializationContext.class);
            final Class<?> jsonType = deserialeMethod.getReturnType();
            //noinspection unchecked
            magic.addDeserializer(jsonType, (JsonDeserializer) deserializer);
        }
        catch(Exception e) {
            throw new IllegalStateException(e);
        }
    }

    mapper.registerModule(magic);
}
 
开发者ID:NovaOrdis,项目名称:playground,代码行数:29,代码来源:BasicObjectMapperProvider.java

示例12: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {

    // validate enum class
    if (enumClass == null) {
        throw new JsonMappingException("Unable to parse unknown pick-list type");
    }

    final String listValue = jp.getText();

    try {
        // parse the string of the form value1;value2;...
        final String[] value = listValue.split(";");
        final int length = value.length;
        final Object resultArray = Array.newInstance(enumClass, length);
        for (int i = 0; i < length; i++) {
            // use factory method to create object
            Array.set(resultArray, i, factoryMethod.invoke(null, value[i].trim()));
        }

        return resultArray;
    } catch (Exception e) {
        throw new JsonParseException("Exception reading multi-select pick list value", jp.getCurrentLocation(), e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:MultiSelectPicklistDeserializer.java

示例13: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@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());
       }
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:18,代码来源:NodeRefDeserializer.java

示例14: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Dpid deserialize(JsonParser jp,
                        DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    Dpid dpid = 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);
            dpid = new Dpid(value);
        }
    }
    return dpid;
}
 
开发者ID:opennetworkinglab,项目名称:spring-open,代码行数:19,代码来源:DpidDeserializer.java

示例15: deserialize

import org.codehaus.jackson.map.DeserializationContext; //导入依赖的package包/类
@Override
public Website deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    JsonNode nodes = oc.readTree(jp);
    String websitePushID = nodes.get("websitePushID").getTextValue();
    String websiteName = nodes.get("websiteName").getTextValue();
    List<String> allowedDomains = new ArrayList<String>();
    for (JsonNode node : nodes.get("allowedDomains")) {
        allowedDomains.add(node.getTextValue());
    }
    String urlFormatString = nodes.get("urlFormatString").getTextValue();
    String authenticationToken = nodes.get("authenticationToken").getTextValue();
    String webServiceUrl = nodes.get("webServiceURL").getTextValue();

    return new WebsiteBuilder()
            .setWebsiteName(websiteName)
            .setWebsitePushId(websitePushID)
            .setAllowedDomains(allowedDomains)
            .setUrlFormatString(urlFormatString)
            .setAuthenticationToken(authenticationToken)
            .setWebServiceUrl(webServiceUrl)
            .build();
}
 
开发者ID:chriskearney,项目名称:stickypunch,代码行数:24,代码来源:WebsiteDeserializer.java


注:本文中的org.codehaus.jackson.map.DeserializationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。