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

com.antiaction.common.json.JSONObjectMapping Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
/*
 * JSON library.
 * Copyright 2012-2013 Antiaction (http://antiaction.com/)
 *
 * 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.antiaction.common.json;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * A JSON object mapping description.
 *
 * @author Nicholas
 * Created on 22/11/2012
 */
public class JSONObjectMapping {

	/** Object mapping type. */
	public static final int OMT_OBJECT = 1;
	/** Array mapping type. */
	public static final int OMT_ARRAY = 2;

	/** Mapping type, object or array. */
	public int type;

	/*
	 * Object.
	 */

	/** Field names to ignore when mapping objects. */
	public Set ignore = new HashSet();

	/** Field names which can be null. */
	public Set nullableSet = new TreeSet();

	/** Field names which can have null values. */
	public Set nullValuesSet = new TreeSet();

	/** Map of mapped fields. */
	public Map fieldMappingsMap = new TreeMap();

	/** List of mapped fields. */
	public List fieldMappingsList = new LinkedList();

	/** Array of mapped fields. */
	public JSONObjectFieldMapping[] fieldMappingsArr;

	/** Boolean indicating if one or more field mapping(s) requires a converter. */
	public boolean converters;

	/*
	 * Array.
	 */

	/** JSON Java array type identifier. */
	public int arrayType;

	/** Field class type name. */
	public String className;

	/** Field class. */
	public Class clazz;

	/** Field object mapping, if object type. */
	public JSONObjectMapping objectMapping;

	private JSONObjectMapping() {
	}

	public static JSONObjectMapping getObjectMapping() {
		JSONObjectMapping om = new JSONObjectMapping();
		om.type = OMT_OBJECT;
		om.ignore = new HashSet();
		om.nullableSet = new TreeSet();
		om.nullValuesSet = new TreeSet();
		om.fieldMappingsMap = new TreeMap();
		om.fieldMappingsList = new LinkedList();
		return om;
	}

	public static JSONObjectMapping getArrayMapping() {
		JSONObjectMapping om = new JSONObjectMapping();
		om.type = OMT_ARRAY;
		return om;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy