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.
/*
* Copyright 2011-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.protocol.json.internal;
import com.amazonaws.annotation.SdkInternalApi;
import com.amazonaws.internal.SdkInternalList;
import com.amazonaws.internal.SdkInternalMap;
import com.amazonaws.protocol.MarshallLocation;
import com.amazonaws.protocol.MarshallingInfo;
import com.amazonaws.protocol.StructuredPojo;
import com.amazonaws.protocol.json.StructuredJsonGenerator;
import com.amazonaws.protocol.json.StructuredJsonMarshaller;
import com.amazonaws.util.TimestampFormat;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;
import java.util.Map;
@SdkInternalApi
public class SimpleTypeJsonMarshallers {
/**
* If the marshallingInfo is null, we are in a container (not a top level member) and should preserve
* JSON null.
*
* Otherwise, we're at the top level and if it's an explicit payload member (which also means that
* marshallLocationName is null) the member should be rendered using the empty body marshaller.
*
* In other cases, do nothing.
*/
public static final JsonMarshaller NULL = new JsonMarshaller() {
@Override
public void marshall(Void val, JsonMarshallerContext context, MarshallingInfo marshallingInfo) {
if (marshallingInfo == null) {
context.jsonGenerator().writeNull();
}
else if (marshallingInfo.isExplicitPayloadMember()) {
if (marshallingInfo.marshallLocationName() != null) {
throw new IllegalStateException("Expected marshalling location name to be null if explicit member is null");
}
context.emptyBodyJsonMarshaller().marshall(context.jsonGenerator());
}
}
};
public static final JsonMarshaller STRING = new BaseJsonMarshaller() {
@Override
public void marshall(String val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller INTEGER = new BaseJsonMarshaller() {
@Override
public void marshall(Integer val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller LONG = new BaseJsonMarshaller() {
@Override
public void marshall(Long val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller SHORT = new BaseJsonMarshaller() {
@Override
public void marshall(Short val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller FLOAT = new BaseJsonMarshaller() {
@Override
public void marshall(Float val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller BIG_DECIMAL = new BaseJsonMarshaller() {
@Override
public void marshall(BigDecimal val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller DOUBLE = new BaseJsonMarshaller() {
@Override
public void marshall(Double val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller BOOLEAN = new BaseJsonMarshaller() {
@Override
public void marshall(Boolean val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller DATE = new BaseJsonMarshaller() {
@Override
public void marshall(Date val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
TimestampFormat timestampFormat = TimestampFormat.UNIX_TIMESTAMP;
if (marshallingInfo != null && marshallingInfo.timestampFormat() != null) {
timestampFormat = marshallingInfo.timestampFormat();
}
jsonGenerator.writeValue(val, timestampFormat);
}
};
public static final JsonMarshaller BYTE_BUFFER = new BaseJsonMarshaller() {
@Override
public void marshall(ByteBuffer val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeValue(val);
}
};
public static final JsonMarshaller STRUCTURED = new BaseJsonMarshaller() {
@Override
public void marshall(StructuredPojo val, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeStartObject();
val.marshall(context.protocolHandler());
jsonGenerator.writeEndObject();
}
};
public static final JsonMarshaller LIST = new BaseJsonMarshaller() {
@Override
public void marshall(List list, StructuredJsonGenerator jsonGenerator, JsonMarshallerContext context,
MarshallingInfo marshallingInfo) {
jsonGenerator.writeStartArray();
for (Object listValue : list) {
context.marshall(MarshallLocation.PAYLOAD, listValue);
}
jsonGenerator.writeEndArray();
}
@Override
protected boolean shouldEmit(List list) {
return !(list.isEmpty() && list instanceof SdkInternalList && ((SdkInternalList) list).isAutoConstruct());
}
};
/**
* Marshalls a Map as a JSON object where each key becomes a field.
*/
public static final JsonMarshaller