當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。