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.
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.jsync.json;
import io.jsync.json.impl.Base64;
import io.jsync.json.impl.Json;
import java.util.*;
/**
* Represents a JSON object.
* Instances of this class are not thread-safe.
*
* @author Tim Fox
*/
public class JsonObject extends JsonElement {
final Map map;
/**
* Create a JSON object based on the specified Map
*
* @param map
*/
public JsonObject(Map map) {
this.map = map;
}
/**
* Create an empty JSON object
*/
public JsonObject() {
this.map = new LinkedHashMap<>();
}
/**
* Create a JSON object from a string form of a JSON object
*
* @param jsonString The string form of a JSON object
*/
public JsonObject(String jsonString) {
map = Json.decodeValue(jsonString, Map.class);
}
@SuppressWarnings("unchecked")
static Map convertMap(Map map) {
Map converted = new LinkedHashMap<>(map.size());
for (Map.Entry entry : map.entrySet()) {
Object obj = entry.getValue();
if (obj instanceof Map) {
Map jm = (Map) obj;
converted.put(entry.getKey(), convertMap(jm));
} else if (obj instanceof List) {
List