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.
package com.cedarsoftware.io;
import java.io.Closeable;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.cedarsoftware.util.ClassUtilities;
import com.cedarsoftware.util.Convention;
import com.cedarsoftware.util.FastByteArrayInputStream;
import com.cedarsoftware.util.FastReader;
import com.cedarsoftware.util.convert.Converter;
/**
* Read an object graph in JSON format and make it available in Java objects, or
* in a "Map of Maps." (untyped representation). This code handles cyclic references
* and can deserialize any Object graph without requiring a class to be 'Serializable'
* or have any specific methods on it. It will handle classes with non-public constructors.
*
* Usages:
*
* Call the static method: {@code JsonReader.jsonToJava(String json)}. This will
* return a typed Java object graph.
*
* Call the static method: {@code JsonReader.jsonToMaps(String json)}. This will
* return an untyped object representation of the JSON String as a Map of Maps, where
* the fields are the Map keys, and the field values are the associated Map's values. You can
* call the JsonWriter.objectToJson() method with the returned Map, and it will serialize
* the Graph into the equivalent JSON stream from which it was read.
*
* Instantiate the JsonReader with an InputStream: {@code JsonReader(InputStream in)} and then call
* {@code readObject()}. Cast the return value of readObject() to the Java class that was the root of
* the graph.
*
*
* Instantiate the JsonReader with an InputStream: {@code JsonReader(InputStream in, true)} and then call
* {@code readObject()}. The return value will be a Map of Maps.
*
*
* @author John DeRegnaucourt ([email protected])
*
* Copyright (c) Cedar Software LLC
*
* 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
*
* 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.
*/
public class JsonReader implements Closeable
{
private final FastReader input;
private final Resolver resolver;
private final ReadOptions readOptions;
private final JsonParser parser;
/**
* Subclass this interface and create a class that will return a new instance of the
* passed in Class (c). Your factory subclass will be called when json-io encounters an
* instance of (c) which you register with JsonReader.assignInstantiator().
* Use the passed in JsonObject o which is a JsonObject to source values for the construction
* of your class.
*/
public interface ClassFactory
{
/**
* Implement this method to return a new instance of the passed in Class. Use the passed
* in JsonObject to supply values to the construction of the object.
*
* @param c Class of the object that needs to be created
* @param jObj JsonObject (if primitive type do jObj.getPrimitiveValue();
* @param resolver Resolve instance that has references to ID Map, Converter, ReadOptions
* @return a new instance of C. If you completely fill the new instance using
* the value(s) from object, and no further work is needed for construction, then
* override the isObjectFinal() method below and return true.
*/
default Object newInstance(Class> c, JsonObject jObj, Resolver resolver) {
return MetaUtils.newInstance(resolver.getConverter(), c, null);
}
/**
* @return true if this object is instantiated and completely filled using the contents
* from the Object [a JsonObject or value]. In this case, no further processing
* will be performed on the instance. If the object has sub-objects (complex fields),
* then return false so that the JsonReader will continue on filling out the remaining
* portion of the object.
*/
default boolean isObjectFinal() {
return false;
}
default void gatherRemainingValues(Resolver resolver, JsonObject jObj, List