All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.landawn.abacus.parser.JSONDeserializationConfig Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.2.4
Show newest version
/*
 * Copyright (C) 2015 HaiYang Li
 *
 * 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.landawn.abacus.parser;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.landawn.abacus.annotation.SuppressFBWarnings;
import com.landawn.abacus.util.N;

/**
 *
 * @author Haiyang Li
 * @since 0.8
 */
public class JSONDeserializationConfig extends DeserializationConfig {

    boolean ignoreNullOrEmpty = false;

    boolean readNullToEmpty = false;

    @SuppressWarnings("rawtypes")
    Class mapInstanceType = HashMap.class;

    /**
     * 
     *
     * @return 
     */
    public boolean ignoreNullOrEmpty() {
        return ignoreNullOrEmpty;
    }

    /**
     * Won't set/add/put the value to bean/array/list/map if it's null or empty {@code CharSequence/Array/Collection/Map}.
     *
     * @param ignoreNullOrEmpty 
     * @return 
     */
    public JSONDeserializationConfig ignoreNullOrEmpty(boolean ignoreNullOrEmpty) {
        this.ignoreNullOrEmpty = ignoreNullOrEmpty;

        return this;
    }

    /**
     * 
     *
     * @return 
     * @deprecated Use {@link #readNullToEmpty()} instead
     */
    @Deprecated
    public boolean nullToEmpty() {
        return readNullToEmpty();
    }

    /**
     * Deserialize the values to empty {@code CharSequence/Array/Collection/Map}, instead of null.
     *
     * @param nullToEmpty
     * @return
     * @deprecated Use {@link #readNullToEmpty(boolean)} instead
     */
    @Deprecated
    public JSONDeserializationConfig nullToEmpty(boolean nullToEmpty) {
        return readNullToEmpty(nullToEmpty);
    }

    /**
     * 
     *
     * @return 
     */
    public boolean readNullToEmpty() {
        return readNullToEmpty;
    }

    /**
     * Deserialize the values to empty {@code CharSequence/Array/Collection/Map}, instead of null.
     *
     * @param readNullToEmpty
     * @return
     */
    public JSONDeserializationConfig readNullToEmpty(boolean readNullToEmpty) {
        this.readNullToEmpty = readNullToEmpty;

        return this;
    }

    /**
     * 
     *
     * @return 
     */
    @SuppressWarnings("rawtypes")
    public Class getMapInstanceType() {
        return mapInstanceType;
    }

    /**
     * 
     *
     * @param mapInstanceType 
     * @return 
     */
    @SuppressWarnings("rawtypes")
    public JSONDeserializationConfig setMapInstanceType(Class mapInstanceType) {
        N.checkArgNotNull(mapInstanceType, "mapInstanceType");

        this.mapInstanceType = mapInstanceType;

        return this;
    }

    //    /**
    //     *
    //     * @return
    //     */
    //    @Override
    //    public JSONDeserializationConfig copy() {
    //        final JSONDeserializationConfig copy = new JSONDeserializationConfig();
    //
    //        copy.setIgnoredPropNames(this.getIgnoredPropNames());
    //        copy.ignoreUnmatchedProperty = this.ignoreUnmatchedProperty;
    //        copy.ignoreNullOrEmpty = this.ignoreNullOrEmpty;
    //        copy.nullToEmpty = this.nullToEmpty;
    //        copy.elementType = this.elementType;
    //        copy.keyType = this.keyType;
    //        copy.valueType = this.valueType;
    //        copy.propTypes = this.propTypes;
    //
    //        return copy;
    //    }

    /**
     * 
     *
     * @return 
     */
    @Override
    public int hashCode() {
        int h = 17;
        h = 31 * h + N.hashCode(getIgnoredPropNames());
        h = 31 * h + N.hashCode(ignoreUnmatchedProperty);
        h = 31 * h + N.hashCode(ignoreNullOrEmpty);
        h = 31 * h + N.hashCode(readNullToEmpty);
        h = 31 * h + N.hashCode(elementType);
        h = 31 * h + N.hashCode(keyType);
        h = 31 * h + N.hashCode(valueType);
        h = 31 * h + N.hashCode(propTypes);
        return 31 * h + N.hashCode(mapInstanceType);
    }

    /**
     *
     * @param obj
     * @return true, if successful
     */
    @SuppressFBWarnings
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof JSONDeserializationConfig other) {
            if (N.equals(getIgnoredPropNames(), other.getIgnoredPropNames()) && N.equals(ignoreUnmatchedProperty, other.ignoreUnmatchedProperty) //NOSONAR
                    && N.equals(ignoreNullOrEmpty, other.ignoreNullOrEmpty) && N.equals(readNullToEmpty, other.readNullToEmpty)
                    && N.equals(elementType, other.elementType) && N.equals(keyType, other.keyType) && N.equals(valueType, other.valueType)
                    && N.equals(propTypes, other.propTypes) && N.equals(mapInstanceType, other.mapInstanceType)) {

                return true;
            }
        }

        return false;
    }

    /**
     * 
     *
     * @return 
     */
    @Override
    public String toString() {
        return "{ignoredPropNames=" + N.toString(getIgnoredPropNames()) + ", ignoreUnmatchedProperty=" + N.toString(ignoreUnmatchedProperty)
                + ", ignoreNullOrEmpty=" + N.toString(ignoreNullOrEmpty) + ", readNullToEmpty=" + N.toString(readNullToEmpty) + ", elementType="
                + N.toString(elementType) + ", keyType=" + N.toString(keyType) + ", valueType=" + N.toString(valueType) + ", propTypes=" + N.toString(propTypes)
                + ", mapInstanceType=" + N.toString(mapInstanceType) + "}";
    }

    /**
     * The Class JDC.
     */
    public static final class JDC extends JSONDeserializationConfig {

        /**
         *
         * @return
         */
        public static JSONDeserializationConfig create() {
            return new JSONDeserializationConfig();
        }

        /**
         *
         * @param elementClass
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(Class elementClass) {
            return create().setElementType(elementClass);
        }

        /**
         *
         * @param keyClass
         * @param valueClass
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(Class keyClass, Class valueClass) {
            return create().setMapKeyType(keyClass).setMapValueType(valueClass);
        }

        /**
         *
         * @param ignoreUnmatchedProperty
         * @param ignoredPropNames
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(boolean ignoreUnmatchedProperty, Map, Set> ignoredPropNames) {
            return create().ignoreUnmatchedProperty(ignoreUnmatchedProperty).setIgnoredPropNames(ignoredPropNames);
        }

        /**
         *
         * @param elementClass
         * @param ignoreUnmatchedProperty
         * @param ignoredPropNames
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(Class elementClass, boolean ignoreUnmatchedProperty, Map, Set> ignoredPropNames) {
            return create().setElementType(elementClass).ignoreUnmatchedProperty(ignoreUnmatchedProperty).setIgnoredPropNames(ignoredPropNames);
        }

        /**
         *
         * @param keyClass
         * @param valueClass
         * @param ignoreUnmatchedProperty
         * @param ignoredPropNames
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(Class keyClass, Class valueClass, boolean ignoreUnmatchedProperty,
                Map, Set> ignoredPropNames) {
            return create().setMapKeyType(keyClass)
                    .setMapValueType(valueClass)
                    .ignoreUnmatchedProperty(ignoreUnmatchedProperty)
                    .setIgnoredPropNames(ignoredPropNames);
        }

        /**
         *
         * @param elementClass
         * @param keyClass
         * @param valueClass
         * @param ignoreUnmatchedProperty
         * @param ignoredPropNames
         * @return
         * @deprecated to be removed in future version.
         */
        @Deprecated
        public static JSONDeserializationConfig of(Class elementClass, Class keyClass, Class valueClass, boolean ignoreUnmatchedProperty,
                Map, Set> ignoredPropNames) {
            return create().setElementType(elementClass)
                    .setMapKeyType(keyClass)
                    .setMapValueType(valueClass)
                    .ignoreUnmatchedProperty(ignoreUnmatchedProperty)
                    .setIgnoredPropNames(ignoredPropNames);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy