本文整理匯總了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()};
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}