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.util.io
import groovy.transform.CompileStatic
import java.sql.Timestamp
import java.util.concurrent.ConcurrentHashMap
import static java.util.Map.Entry
/**
* Read an object graph in JSON format and make it available in Groovy 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 'Serializeable'
* or have any specific methods on it. It will handle classes with non public constructors.
*
* Usages:
*
* Call the static method: {@code GroovyJsonReader.jsonToGroovy(String json)}. This will
* return a typed Groovy object graph.
*
* Call the static method: {@code GroovyJsonReader.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 GroovyJsonWriter.objectToJson() method with the returned Map, and it will serialize
* the Graph into the identical JSON stream from which it was read.
*
* Instantiate the GroovyJsonReader with an InputStream: {@code GroovyJsonReader(InputStream in)} and then call
* {@code readObject()}. Cast the return value of readObject() to the Groovy class that was the root of
* the graph.
*
*
* Instantiate the GroovyJsonReader with an InputStream: {@code GroovyJsonReader(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
*
* 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.
*/
@CompileStatic
class GroovyJsonReader implements Closeable
{
static final String USE_MAPS = "USE_MAPS" // If set, the read-in JSON will be turned into a Map of Maps (JsonObject) representation
static final String UNKNOWN_OBJECT = "UNKNOWN_OBJECT"; // What to do when an object is found and 'type' cannot be determined.
static final String TYPE_NAME_MAP = "TYPE_NAME_MAP" // If set, this map will be used when writing @type values - allows short-hand abbreviations type names
static final String TYPE_NAME_MAP_REVERSE = "TYPE_NAME_MAP_REVERSE" // This map is the reverse of the TYPE_NAME_MAP (value -> key)
protected static final Map readers = [
(String.class):new Readers.StringReader(),
(Date.class):new Readers.DateReader(),
(BigInteger.class):new Readers.BigIntegerReader(),
(BigDecimal.class):new Readers.BigDecimalReader(),
(java.sql.Date.class):new Readers.SqlDateReader(),
(Timestamp.class):new Readers.TimestampReader(),
(Calendar.class):new Readers.CalendarReader(),
(TimeZone.class):new Readers.TimeZoneReader(),
(Locale.class):new Readers.LocaleReader(),
(Class.class):new Readers.ClassReader(),
(StringBuilder.class):new Readers.StringBuilderReader(),
(StringBuffer.class):new Readers.StringBufferReader()
] as ConcurrentHashMap
protected static final Set notCustom = new HashSet<>()
private static final Map factory = new ConcurrentHashMap<>();
private final Map objsRead = new HashMap<>()
private final FastPushbackReader input
static final ThreadLocal threadInput = new ThreadLocal<>()
// _args is using ThreadLocal so that static inner classes can have access to them
static final ThreadLocal