com.urbanairship.api.common.parse.StandardObjectDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
The Urban Airship Java client library
/*
* Copyright (c) 2013-2016. Urban Airship and Contributors
*/
package com.urbanairship.api.common.parse;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.google.common.base.Supplier;
import java.io.IOException;
import java.util.Optional;
public class StandardObjectDeserializer> {
private final FieldParserRegistry registry;
private final Supplier readerSupplier;
public StandardObjectDeserializer(FieldParserRegistry registry, Supplier readerSupplier) {
this.registry = registry;
this.readerSupplier = readerSupplier;
}
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonToken token = jp.getCurrentToken();
if (token == JsonToken.START_OBJECT) {
token = jp.nextToken();
}
R reader = readerSupplier.get();
while (token != null && token != JsonToken.END_OBJECT) {
if (token != JsonToken.FIELD_NAME) {
APIParsingException.raise("Parsing of json failed. Expected to be at field name token but was " + token.name(), jp);
}
String name = jp.getCurrentName();
jp.nextToken();
Optional> fieldParser = registry.getFieldParser(name);
if (fieldParser.isPresent()) {
fieldParser.get().parse(reader, jp, ctxt);
}
else {
jp.skipChildren();
}
token = jp.nextToken();
}
return reader.validateAndBuild();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy