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 2010 Proofpoint, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.facebook.airlift.json;
import com.facebook.airlift.json.LengthLimitedWriter.LengthLimitExceededException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Suppliers;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
public class JsonCodec
implements Codec
{
private static final Supplier OBJECT_MAPPER_SUPPLIER = Suppliers.memoize(
() -> new JsonObjectMapperProvider().get().enable(INDENT_OUTPUT))::get;
public static JsonCodec jsonCodec(Class type)
{
requireNonNull(type, "type is null");
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), type);
}
public static JsonCodec jsonCodec(TypeToken type)
{
requireNonNull(type, "type is null");
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), type.getType());
}
public static JsonCodec> listJsonCodec(Class type)
{
requireNonNull(type, "type is null");
Type listType = new TypeToken>() {}
.where(new TypeParameter() {}, type)
.getType();
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), listType);
}
public static JsonCodec> listJsonCodec(JsonCodec type)
{
requireNonNull(type, "type is null");
Type listType = new TypeToken>() {}
.where(new TypeParameter() {}, type.getTypeToken())
.getType();
return new JsonCodec<>(OBJECT_MAPPER_SUPPLIER.get(), listType);
}
public static JsonCodec