null
+ */
+ public OrderedJSONObject(Map, ?> m) {
+ super(m);
+ }
+
+ /**
+ * Construct a JSONObject from an Object using bean getters. It reflects on
+ * all of the public methods of the object. For each of the methods with no
+ * parameters and a name starting with "get" or
+ * "is" followed by an uppercase letter, the method is invoked,
+ * and a key and the value returned from the getter method are put into the
+ * new JSONObject.
+ *
+ * The key is formed by removing the "get" or "is"
+ * prefix. If the second remaining character is not upper case, then the
+ * first character is converted to lower case.
+ *
+ * Methods that are static, return void,
+ * have parameters, or are "bridge" methods, are ignored.
+ *
+ * For example, if an object has a method named "getName", and
+ * if the result of calling object.getName() is
+ * "Larry Fine", then the JSONObject will contain
+ * "name": "Larry Fine".
+ *
+ * The {@link JSONPropertyName} annotation can be used on a bean getter to
+ * override key name used in the JSONObject. For example, using the object
+ * above with the getName method, if we annotated it with:
+ *
+ * @JSONPropertyName("FullName")
+ * public String getName() { return this.name; }
+ *
+ * The resulting JSON object would contain "FullName": "Larry Fine"
+ *
+ * Similarly, the {@link JSONPropertyName} annotation can be used on non-
+ * get and is methods. We can also override key
+ * name used in the JSONObject as seen below even though the field would normally
+ * be ignored:
+ *
+ * @JSONPropertyName("FullName")
+ * public String fullName() { return this.name; }
+ *
+ * The resulting JSON object would contain "FullName": "Larry Fine"
+ *
+ * The {@link JSONPropertyIgnore} annotation can be used to force the bean property
+ * to not be serialized into JSON. If both {@link JSONPropertyIgnore} and
+ * {@link JSONPropertyName} are defined on the same method, a depth comparison is
+ * performed and the one closest to the concrete class being serialized is used.
+ * If both annotations are at the same level, then the {@link JSONPropertyIgnore}
+ * annotation takes precedent and the field is not serialized.
+ * For example, the following declaration would prevent the getName
+ * method from being serialized:
+ *
+ * @JSONPropertyName("FullName")
+ * @JSONPropertyIgnore
+ * public String getName() { return this.name; }
+ *
+ *
+ *
+ * @param bean An object that has getter methods that should be used to make
+ * a JSONObject.
+ */
+ public OrderedJSONObject(Object bean) {
+ super(bean);
+ }
+
+ /**
+ * Construct a JSONObject from an Object, using reflection to find the
+ * public members. The resulting JSONObject's keys will be the strings from
+ * the names array, and the values will be the field values associated with
+ * those keys in the object. If a key is not found or not visible, then it
+ * will not be copied into the new JSONObject.
+ *
+ * @param object An object that has fields that should be used to make a
+ * JSONObject.
+ * @param names An array of strings, the names of the fields to be obtained
+ */
+ public OrderedJSONObject(Object object, String... names) {
+ super(object, names);
+ }
+
+ /**
+ * Construct a JSONObject from a source JSON text string. This is the most
+ * commonly used JSONObject constructor.
+ *
+ * @param source A string beginning with { (left
+ * brace) and ending with }
+ * (right brace).
+ * @throws JSONException If there is a syntax error in the source string or a
+ * duplicated key.
+ */
+ public OrderedJSONObject(String source) throws JSONException {
+ super(source);
+ }
+
+ /**
+ * Construct a JSONObject from a ResourceBundle.
+ *
+ * @param baseName The ResourceBundle base name.
+ * @param locale The Locale to load the ResourceBundle for.
+ * @throws JSONException If any JSONExceptions are detected.
+ */
+ public OrderedJSONObject(String baseName, Locale locale) throws JSONException {
+ super(baseName, locale);
+ }
+
+ /**
+ * Constructor to specify an initial capacity of the internal map. Useful for library
+ * internal calls where we know, or at least can best guess, how big this JSONObject
+ * will be.
+ *
+ * @param initialCapacity initial capacity of the internal map.
+ */
+ protected OrderedJSONObject(int initialCapacity) {
+ super(initialCapacity);
+ }
+
+ //endregion
+
+ /**
+ * Returns the factory used to create the map
+ */
+ @Override
+ protected MapFactory getMapFactory() {
+ return OrderedMapFactory.getInstance();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/json/OrderedMapFactory.java b/src/main/java/org/json/OrderedMapFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..d7fabf7e79855a960ec513760e4b6d9053973735
--- /dev/null
+++ b/src/main/java/org/json/OrderedMapFactory.java
@@ -0,0 +1,45 @@
+package org.json;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * A MapFactory produces ordered maps
+ *
+ * @author Cathy Zhou
+ */
+public class OrderedMapFactory implements MapFactory {
+ private OrderedMapFactory() {
+ }
+
+ /**
+ * Create an instance of Map
+ */
+ @Override
+ public Map