Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package software.amazon.jsii;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
import com.fasterxml.jackson.databind.deser.ContextualDeserializer;
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.module.SimpleSerializers;
import com.fasterxml.jackson.databind.type.MapLikeType;
import com.fasterxml.jackson.databind.type.MapType;
import org.jetbrains.annotations.Nullable;
/**
* Provides a correctly configured JSON processor for handling JSII requests and responses.
*/
@Internal
public final class JsiiObjectMapper {
/**
* An ObjectMapper that can be used to serialize and deserialize JSII requests and responses.
*/
public static final ObjectMapper INSTANCE = new JsiiObjectMapper().getObjectMapper();
/**
* Similar to calling JsiiObjectMapper.INSTANCE.treeToValue, but handles a null JsonNode argument
* well, and throws JsiiError instead of JsonProcessingException.
*
* @param tree the JSON object to parse
* @param valueType the expected type value type
* @param expected type
* @return the deserialized value
*/
public static T treeToValue(final JsonNode tree, final NativeType valueType) {
if (tree == null) {
return null;
}
final Object result = INSTANCE.convertValue(tree, valueType.getJavaType());
return valueType.transform(result);
}
/**
* Similar to calling JsiiObjectMapper.INSTANCE.valueToTree, but handles a null argument well by
* returning null.
*
* @param value the value to serialize
* @param expected JSON type
* @return the JSON object
*/
public static T valueToTree(final Object value) {
if (value == null) {
return null;
}
return INSTANCE.valueToTree(value);
}
private static final String TOKEN_REF = JsiiObjectRef.TOKEN_REF;
private static final String TOKEN_DATE = "$jsii.date";
private static final String TOKEN_ENUM = "$jsii.enum";
private static final String TOKEN_MAP = "$jsii.map";
private final ObjectMapper objectMapper;
@Nullable
private final JsiiEngine jsiiEngine;
private JsiiObjectMapper() {
this(null);
}
JsiiObjectMapper(@Nullable final JsiiEngine jsiiEngine) {
this.jsiiEngine = jsiiEngine;
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(Include.NON_NULL);
final SimpleModule module = new SimpleModule("JSII", Version.unknownVersion());
module.setDeserializerModifier(new JsiiDeserializerModifier());
module.setSerializers(new JsiiSerializers());
module.addSerializer(Enum.class, new EnumSerializer());
module.addSerializer(Instant.class, new InstantSerializer());
module.addSerializer(JsiiSerializable.class, new JsiiSerializer());
this.objectMapper.findAndRegisterModules();
this.objectMapper.registerModule(module);
}
ObjectMapper getObjectMapper() {
return this.objectMapper;
}
private JsiiEngine getEngine() {
if (this.jsiiEngine != null) {
return this.jsiiEngine;
}
return JsiiEngine.getInstance();
}
/**
* A JsonDeserializer designed to correctly handle JSII "magic objects" that are used to remodel "pass-by-reference"
* values, dates, and enum constants.
*/
private final class JsiiDeserializer extends StdDeserializer