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


Java DeserializationContext类代码示例

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


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

示例1: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
    throws IOException, JsonProcessingException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node instanceof ArrayNode) {
    ArrayNode arrayNode = (ArrayNode) node;
    ArrayList<String> ret = new ArrayList<>();
    for (int i = 0; i < arrayNode.size(); i++) {
      ret.add(arrayNode.get(i).textValue());
    }
    return ret.toArray(new String[0]);
  } else {
    return new String[]{node.textValue()};
  }

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:18,代码来源:StringArrayOrElementStringDeserializer.java

示例2: getOnType

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
/** Get type for  "on" values that are plain URIs by deducing the type from their parent. */
private String getOnType(DeserializationContext ctxt) {
  // Easiest way: The parser has already constructed an annotation object with a motivation.
  // This is highly dependendant on the order of keys in the JSON, i.e. if "on" is the first key in the annotation
  // object, this won't work.
  Object curVal = ctxt.getParser().getCurrentValue();
  boolean isPaintingAnno = (curVal != null && curVal instanceof Annotation &&
                            ((Annotation) curVal).getMotivation() != null &&
                            ((Annotation) curVal).getMotivation().equals(Motivation.PAINTING));
  if (isPaintingAnno) {
      return "sc:Canvas";
  }
  // More reliable way: Walk up the parsing context until we hit a IIIF resource that we can deduce the type from
  // Usually this shouldn't be more than two levels up
  JsonStreamContext parent = ctxt.getParser().getParsingContext().getParent();
  while (parent != null && (parent.getCurrentValue() == null || !(parent.getCurrentValue() instanceof Resource))) {
    parent = parent.getParent();
  }
  if (parent != null) {
    Resource parentObj = (Resource) parent.getCurrentValue();
    return parentObj.getType();
  }
  return null;
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:25,代码来源:ResourceDeserializer.java

示例3: handleUnexpectedToken

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public Object handleUnexpectedToken(DeserializationContext ctxt, Class<?> targetType, JsonToken t, JsonParser p,
    String failureMsg) throws IOException {
  if (p.getCurrentName().equals("@type") && t == JsonToken.START_ARRAY) {
    // Handle multi-valued @types, only current known cases are oa:SvgSelector and oa:CssStyle
    // in combination with cnt:ContentAsText
    ObjectMapper mapper = (ObjectMapper) p.getCodec();
    String typeName = StreamSupport.stream(((ArrayNode) mapper.readTree(p)).spliterator(), false)
        .map(JsonNode::textValue)
        .filter(v -> !v.equals(ContentAsText.TYPE))
        .findFirst().orElse(null);
    if (typeName != null) {
      return typeName;
    }
  }
  return super.handleUnexpectedToken(ctxt, targetType, t, p, failureMsg);
}
 
开发者ID:dbmdz,项目名称:iiif-apis,代码行数:18,代码来源:ProblemHandler.java

示例4: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public KeyValue deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
  JsonNode node = objectMapper.getFactory().setCodec(objectMapper).getCodec().readTree(jp);

  String key = node.get("key").asText();
  String type = node.get("type").asText();

  KeyValue keyValue = new KeyValue();
  keyValue.setKey(key);
  keyValue.setValueType(type);

  if ("string".equalsIgnoreCase(type)) {
    keyValue.setValueString(node.get("value").asText());
  } else if ("boolean".equalsIgnoreCase(type)) {
    keyValue.setValueBoolean(node.get("value").asBoolean());
  }

  return keyValue;
}
 
开发者ID:jaegertracing,项目名称:spark-dependencies,代码行数:20,代码来源:KeyValueDeserializer.java

示例5: shouldDeserialiseFromSimpleClassName

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Test
public void shouldDeserialiseFromSimpleClassName() throws IOException, ClassNotFoundException {
    // Given
    final SimpleClassDeserializer deserialiser = new SimpleClassDeserializer();
    final DeserializationContext context = mock(DeserializationContext.class);
    final Class expectedClass = IsA.class;
    final String id = expectedClass.getSimpleName();
    given(context.findClass(expectedClass.getName())).willReturn(expectedClass);

    // When
    final Class<?> clazz = deserialiser._deserialize(id, context);

    // Then
    assertEquals(expectedClass, clazz);
    verify(context).findClass(expectedClass.getName());
}
 
开发者ID:gchq,项目名称:koryphe,代码行数:17,代码来源:SimpleClassDeserializerTest.java

示例6: readExtensions

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
public static <T> List<Extension<T>> readExtensions(JsonParser parser, DeserializationContext context) throws IOException {
    Objects.requireNonNull(parser);
    Objects.requireNonNull(context);

    List<Extension<T>> extensions = new ArrayList<>();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String extensionName = parser.getCurrentName();
        ExtensionJson extensionJson = ExtensionSupplier.findExtensionJson(extensionName);
        if (extensionJson != null) {
            parser.nextToken();
            Extension<T> extension = extensionJson.deserialize(parser, context);
            extensions.add(extension);
        } else {
            skip(parser);
        }
    }

    return extensions;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:21,代码来源:JsonUtil.java

示例7: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public Foo deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    List<Extension<Foo>> extensions = Collections.emptyList();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        if (parser.getCurrentName().equals("extensions")) {
            parser.nextToken();
            extensions = JsonUtil.readExtensions(parser, context);
        }
    }

    Foo foo = new Foo();
    ExtensionSupplier.addExtensions(foo, extensions);

    return foo;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:FooDeserializer.java

示例8: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public PostContingencyResult deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException {
    Contingency contingency = null;
    LimitViolationsResult limitViolationsResult = null;

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        switch (parser.getCurrentName()) {
            case "contingency":
                parser.nextToken();
                contingency = parser.readValueAs(Contingency.class);
                break;

            case "limitViolationsResult":
                parser.nextToken();
                limitViolationsResult = parser.readValueAs(LimitViolationsResult.class);
                break;

            default:
                throw new AssertionError("Unexpected field: " + parser.getCurrentName());
        }
    }

    return new PostContingencyResult(contingency, limitViolationsResult);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:PostContingencyResultDeserializer.java

示例9: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public BeakerCodeCellList deserialize(JsonParser jp, DeserializationContext ctxt) 
    throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper)jp.getCodec();
  JsonNode node = mapper.readTree(jp);
  
  List<BeakerCodeCell> l = new ArrayList<BeakerCodeCell>();
  if (node.isArray()) {
    for (JsonNode o : node) {
      Object obj = objectSerializerProvider.get().deserialize(o, mapper);
      if (obj instanceof BeakerCodeCell)
        l.add((BeakerCodeCell) obj);
    }
  }
  
  BeakerCodeCellList r = new BeakerCodeCellList();
  r.theList = l;
  return r;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:20,代码来源:BeakerCodeCellListDeserializer.java

示例10: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {

    DateTimeFormatter formatter =
            DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]").withZone(ZoneId.of("UTC"));

    String value = p.getValueAsString();
    ZonedDateTime result = null;

    if(value != null) {
        int index;
        if ((index = value.indexOf('.')) > -1) {
            char[] chars = new char[4 - (value.length() - index)];
            Arrays.fill(chars, '0');
            value += new String(chars);
        }
        result = ZonedDateTime.from(formatter.parse(value));
    }

    return result;
}
 
开发者ID:CCob,项目名称:bittrex4j,代码行数:22,代码来源:DateTimeDeserializer.java

示例11: shouldDeserialiseFromSimpleClassName

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Test
public void shouldDeserialiseFromSimpleClassName() throws IOException, ClassNotFoundException {
    // Given
    final SimpleClassKeyDeserializer deserialiser = new SimpleClassKeyDeserializer();
    final DeserializationContext context = mock(DeserializationContext.class);
    final Class expectedClass = IsA.class;
    final String id = expectedClass.getSimpleName();
    given(context.findClass(expectedClass.getName())).willReturn(expectedClass);

    // When
    final Class<?> clazz = (Class<?>) deserialiser.deserializeKey(id, context);

    // Then
    assertEquals(expectedClass, clazz);
    verify(context).findClass(expectedClass.getName());
}
 
开发者ID:gchq,项目名称:koryphe,代码行数:17,代码来源:SimpleClassKeyDeserializerTest.java

示例12: initMasterClient

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
private static void initMasterClient() {
  JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
  ObjectMapper objectMapper = JSONUtil.prettyMapper();
  objectMapper.registerModule(
    new SimpleModule()
      .addDeserializer(JobDataFragment.class,
        new JsonDeserializer<JobDataFragment>() {
          @Override
          public JobDataFragment deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return jsonParser.readValueAs(DataPOJO.class);
          }
        }
      )
  );
  provider.setMapper(objectMapper);
  masterClient = ClientBuilder.newBuilder().register(provider).register(MultiPartFeature.class).build();
  WebTarget rootTarget = masterClient.target("http://localhost:" + masterDremioDaemon.getWebServer().getPort());
  masterApiV2 = rootTarget.path(API_LOCATION);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:TestMasterDown.java

示例13: shouldDeserialiseFromFullClassNameForUnknownClass

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Test
public void shouldDeserialiseFromFullClassNameForUnknownClass() throws IOException, ClassNotFoundException {
    // Given
    final SimpleClassDeserializer deserialiser = new SimpleClassDeserializer();
    final DeserializationContext context = mock(DeserializationContext.class);
    final Class expectedClass = UnsignedLong.class;
    final String id = expectedClass.getName();
    given(context.findClass(expectedClass.getName())).willReturn(expectedClass);

    // When
    final Class<?> clazz = deserialiser._deserialize(id, context);

    // Then
    assertEquals(expectedClass, clazz);
    verify(context).findClass(expectedClass.getName());
}
 
开发者ID:gchq,项目名称:koryphe,代码行数:17,代码来源:SimpleClassDeserializerTest.java

示例14: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public String deserialize(final JsonParser parser, final DeserializationContext ctxt)
    throws IOException, JsonProcessingException {
    final boolean hasStringValue = parser.hasToken(JsonToken.VALUE_STRING);

    if (!hasStringValue) {
        return null;
    }

    final String text = parser.getText();

    final String trimmed = text.trim();

    if (trimmed.isEmpty()) {
        return null;
    }

    return trimmed;
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:20,代码来源:StringTrimmingJsonDeserializer.java

示例15: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //导入依赖的package包/类
@Override
public T deserialize(JsonParser jsonParser,
                     DeserializationContext deserializationContext) throws IOException,
        JsonProcessingException {
    ObjectCodec objectCodec = jsonParser.getCodec();
    JsonNode node = objectCodec.readTree(jsonParser);
    Class<? extends T> typeClass = null;
    if (node.isObject() && node.has("type")) {
        JsonNode type = node.get("type");
        if (type != null && type.isTextual()) {
            typeClass = registry.get(type.textValue());
        }
    }

    if (typeClass == null) {
        return null;
    }

    StringWriter writer = new StringWriter();
    objectMapper.writeValue(writer, node);
    writer.close();
    String json = writer.toString();
    return objectMapper.readValue(json, typeClass);
}
 
开发者ID:Esri,项目名称:server-extension-java,代码行数:25,代码来源:AbstractTypedObjectDeserializer.java


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