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.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.johnzon.jsonb;
import org.apache.johnzon.jsonb.adapter.JsonbEnumAdapter;
import org.apache.johnzon.jsonb.api.experimental.PolymorphicConfig;
import org.apache.johnzon.jsonb.cdi.CDIs;
import org.apache.johnzon.jsonb.converter.JohnzonJsonbAdapter;
import org.apache.johnzon.jsonb.factory.SimpleJohnzonAdapterFactory;
import org.apache.johnzon.jsonb.reflect.Types;
import org.apache.johnzon.jsonb.serializer.JohnzonDeserializationContext;
import org.apache.johnzon.jsonb.serializer.JohnzonSerializationContext;
import org.apache.johnzon.jsonb.spi.JohnzonAdapterFactory;
import org.apache.johnzon.mapper.Converter;
import org.apache.johnzon.mapper.Mapper;
import org.apache.johnzon.mapper.MapperBuilder;
import org.apache.johnzon.mapper.MapperConfig;
import org.apache.johnzon.mapper.Mappings;
import org.apache.johnzon.mapper.ObjectConverter;
import org.apache.johnzon.mapper.SerializeValueFilter;
import org.apache.johnzon.mapper.access.AccessMode;
import org.apache.johnzon.mapper.access.FieldAndMethodAccessMode;
import org.apache.johnzon.mapper.converter.LocaleConverter;
import org.apache.johnzon.mapper.internal.AdapterKey;
import jakarta.json.JsonBuilderFactory;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import jakarta.json.bind.adapter.JsonbAdapter;
import jakarta.json.bind.config.BinaryDataStrategy;
import jakarta.json.bind.config.PropertyNamingStrategy;
import jakarta.json.bind.config.PropertyVisibilityStrategy;
import jakarta.json.bind.serializer.JsonbDeserializer;
import jakarta.json.bind.serializer.JsonbSerializer;
import jakarta.json.spi.JsonProvider;
import jakarta.json.stream.JsonGenerator;
import jakarta.json.stream.JsonParserFactory;
import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static java.time.format.DateTimeFormatter.ofPattern;
import static java.util.Collections.emptyMap;
import static java.util.Optional.ofNullable;
import static jakarta.json.bind.config.PropertyNamingStrategy.IDENTITY;
import static jakarta.json.bind.config.PropertyOrderStrategy.ANY;
public class JohnzonBuilder implements JsonbBuilder {
private static final Object NO_BM = new Object();
private final MapperBuilder builder = new MapperBuilder();
private JsonProvider jsonp;
private JsonbConfig config;
private Object beanManager;
private CDIs cdiIntegration;
@Override
public JsonbBuilder withConfig(final JsonbConfig config) {
this.config = config;
return this;
}
@Override
public JsonbBuilder withProvider(final JsonProvider jsonpProvider) {
this.jsonp = jsonpProvider;
return this;
}
@Override
public Jsonb build() {
builder.setEnumConverterFactory(type -> newEnumConverter(Class.class.cast(type)));
if (jsonp != null) {
builder.setGeneratorFactory(jsonp.createGeneratorFactory(generatorConfig()));
builder.setReaderFactory(jsonp.createReaderFactory(readerConfig()));
} else {
jsonp = JsonProvider.provider();
}
final Supplier builderFactorySupplier = createJsonBuilderFactory();
final Supplier parserFactoryProvider = createJsonParserFactory();
if (config == null) {
config = new JsonbConfig();
}
final boolean skipCdi = shouldSkipCdi();
// todo: global spec toggle to disable all these ones at once?
builder.setUseBigDecimalForObjectNumbers(config.getProperty("johnzon.use-big-decimal-for-object").map(this::toBool).orElse(true));
builder.setMaxBigDecimalScale(config.getProperty("johnzon.max-big-decimal-scale").map(this::toInt).orElse(1000));
builder.setSupportEnumContainerDeserialization( // https://github.com/eclipse-ee4j/jakartaee-tck/issues/103
toBool(System.getProperty("johnzon.support-enum-container-deserialization", config.getProperty("johnzon.support-enum-container-deserialization")
.map(String::valueOf).orElse("true"))));
final boolean ijson = config.getProperty(JsonbConfig.STRICT_IJSON)
.map(Boolean.class::cast)
.filter(it -> it)
.map(it -> {
if (!config.getProperty(JsonbConfig.BINARY_DATA_STRATEGY).isPresent()) {
config.withBinaryDataStrategy(BinaryDataStrategy.BASE_64);
}
if (!config.getProperty(JsonbConfig.DATE_FORMAT).isPresent()) {
config.withDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'xxx", Locale.ROOT);
}
return it;
}).orElse(false);
if (config.getProperty(JsonbConfig.FORMATTING).map(Boolean.class::cast).orElse(false)) {
builder.setPretty(true);
}
config.getProperty(PolymorphicConfig.class.getName())
.map(PolymorphicConfig.class::cast)
.ifPresent(pc -> {
builder.setPolymorphicDiscriminator(pc.getDiscriminator());
builder.setPolymorphicDeserializationPredicate(pc.getDeserializationPredicate());
builder.setPolymorphicSerializationPredicate(pc.getSerializationPredicate());
builder.setPolymorphicDiscriminatorMapper(pc.getDiscriminatorMapper());
builder.setPolymorphicTypeLoader(pc.getTypeLoader());
});
config.getProperty(JsonbConfig.ENCODING).ifPresent(encoding -> builder.setEncoding(String.valueOf(encoding)));
final boolean isNillable = config.getProperty(JsonbConfig.NULL_VALUES)
.map(it -> String.class.isInstance(it) ? Boolean.parseBoolean(it.toString()) : Boolean.class.cast(it))
.map(serNulls -> {
builder.setSkipNull(!serNulls);
return serNulls;
})
.orElse(false);
final Optional