congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
JsonArray.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
jodd.json.JsonArray
constructor

Best Java code snippets using jodd.json.JsonArray.<init> (Showing top 20 results out of 315)

origin: oblac/jodd

/**
 * Returns the JsonArray at position {@code pos} in the array.
 */
public JsonArray getJsonArray(final int pos) {
  Object val = list.get(pos);
  if (val instanceof List) {
    val = new JsonArray((List) val);
  }
  return (JsonArray) val;
}
origin: oblac/jodd

/**
 * Returns the {@link JsonArray} value with the specified key
 */
public JsonArray getJsonArray(final String key) {
  Object val = map.get(key);
  if (val instanceof List) {
    val = new JsonArray((List) val);
  }
  return (JsonArray) val;
}
origin: oblac/jodd

/**
 * Parses input JSON to {@link JsonArray}, special case of parsing.
 */
public JsonArray parseAsJsonArray(final String input) {
  return new JsonArray(parse(input));
}
origin: oblac/jodd

@Override
public Object next() {
  Object val = listIter.next();
  if (val instanceof Map) {
    val = new JsonObject((Map) val);
  } else if (val instanceof List) {
    val = new JsonArray((List) val);
  }
  return val;
}
origin: oblac/jodd

/**
 * Removes the value at the specified position in the JSON array.
 */
public Object remove(final int pos) {
  Object removed = list.remove(pos);
  if (removed instanceof Map) {
    return new JsonObject((Map) removed);
  }
  if (removed instanceof ArrayList) {
    return new JsonArray((List) removed);
  }
  return removed;
}
origin: oblac/jodd

/**
 * Returns the object value at position {@code pos} in the array.
 */
public Object getValue(final int pos) {
  Object val = list.get(pos);
  if (val instanceof Map) {
    val = new JsonObject((Map) val);
  }
  else if (val instanceof List) {
    val = new JsonArray((List) val);
  }
  return val;
}
origin: oblac/jodd

/**
 * Returns the value with the specified key, as an object.
 */
@SuppressWarnings("unchecked")
public <T> T getValue(final String key) {
  T val = (T) map.get(key);
  if (val instanceof Map) {
    return (T) new JsonObject((Map) val);
  }
  if (val instanceof List) {
    return (T) new JsonArray((List) val);
  }
  return val;
}
origin: oblac/jodd

@Override
public Map.Entry<String, Object> next() {
  Map.Entry<String, Object> entry = mapIterator.next();
  if (entry.getValue() instanceof Map) {
    return MapEntry.createUnmodifiable(entry.getKey(), new JsonObject((Map) entry.getValue()));
  }
  if (entry.getValue() instanceof List) {
    return MapEntry.createUnmodifiable(entry.getKey(), new JsonArray((List) entry.getValue()));
  }
  return entry;
}
origin: oblac/jodd

@BeforeEach
void setUp() {
  jsonArray = new JsonArray();
}
origin: oblac/jodd

@Test
void testJsonArrayEquality() {
  JsonObject obj = new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3)));
  assertEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3))));
  assertEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3L))));
  assertEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(3))));
  assertEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(3L))));
  assertNotEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(4))));
  assertNotEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(4))));
  JsonArray array = new JsonArray(Collections.singletonList(Collections.singletonList(3)));
  assertEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(3))));
  assertEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(3L))));
  assertEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(3))));
  assertEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(3L))));
  assertNotEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(4))));
  assertNotEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(4))));
}
origin: oblac/jodd

private void assertNumberEquals(Number value1, Number value2) {
  JsonObject o1 = new JsonObject().put("key", value1);
  JsonObject o2 = new JsonObject().put("key", value2);
  if (!o1.equals(o2)) {
    fail("Was expecting " + value1.getClass().getSimpleName() + ":" + value1 + " == " +
      value2.getClass().getSimpleName() + ":" + value2);
  }
  JsonArray a1 = new JsonArray().add(value1);
  JsonArray a2 = new JsonArray().add(value2);
  if (!a1.equals(a2)) {
    fail("Was expecting " + value1.getClass().getSimpleName() + ":" + value1 + " == " +
      value2.getClass().getSimpleName() + ":" + value2);
  }
}
origin: oblac/jodd

@Test
void testCreateFromListCharSequence() {
  List<Object> list = new ArrayList<>();
  list.add("foo");
  list.add(123);
  list.add(new StringBuilder("eek"));
  JsonArray arr = new JsonArray(list);
  assertEquals("foo", arr.getString(0));
  assertEquals(Integer.valueOf(123), arr.getInteger(1));
  assertEquals("eek", arr.getString(2));
  assertSame(list, arr.list());
}
origin: oblac/jodd

@Test
void testCreateFromList() {
  List<Object> list = new ArrayList<>();
  list.add("foo");
  list.add(123);
  JsonArray arr = new JsonArray(list);
  assertEquals("foo", arr.getString(0));
  assertEquals(Integer.valueOf(123), arr.getInteger(1));
  assertSame(list, arr.list());
}
origin: oblac/jodd

@Test
void testCreateFromListNestedList() {
  List<Object> list = new ArrayList<>();
  list.add("foo");
  list.add(123);
  List<Object> list2 = new ArrayList<>();
  list2.add("blah");
  list2.add("wibble");
  list.add(list2);
  JsonArray arr = new JsonArray(list);
  assertEquals("foo", arr.getString(0));
  assertEquals(Integer.valueOf(123), arr.getInteger(1));
  assertSame(list, arr.list());
  JsonArray arr2 = arr.getJsonArray(2);
  assertSame(list2, arr2.list());
}
origin: oblac/jodd

@Test
void testCreateFromListNestedJsonArray() {
  List<Object> list = new ArrayList<>();
  list.add("foo");
  list.add(123);
  JsonArray arr2 = new JsonArray().add("blah").add("wibble");
  list.add(arr2);
  JsonArray arr = new JsonArray(list);
  assertEquals("foo", arr.getString(0));
  assertEquals(Integer.valueOf(123), arr.getInteger(1));
  assertSame(list, arr.list());
  assertSame(arr2, arr.getJsonArray(2));
}
origin: oblac/jodd

@Test
void testCreateFromMapNestedJsonArray() {
  Map<String, Object> map = new HashMap<>();
  JsonArray nestedArr = new JsonArray().add("foo");
  map.put("nested", nestedArr);
  JsonObject obj = new JsonObject(map);
  JsonArray nestedRetrieved = obj.getJsonArray("nested");
  assertEquals("foo", nestedRetrieved.getString(0));
}
origin: oblac/jodd

@Test
void testCreateFromListNestedJsonObject() {
  List<Object> list = new ArrayList<>();
  list.add("foo");
  list.add(123);
  JsonObject obj = new JsonObject().put("blah", "wibble");
  list.add(obj);
  JsonArray arr = new JsonArray(list);
  assertEquals("foo", arr.getString(0));
  assertEquals(Integer.valueOf(123), arr.getInteger(1));
  assertSame(list, arr.list());
  assertSame(obj, arr.getJsonObject(2));
}
origin: oblac/jodd

@Test
void testAddJsonArray() {
  JsonArray arr = new JsonArray().add("foo");
  assertSame(jsonArray, jsonArray.add(arr));
  assertEquals(arr, jsonArray.getJsonArray(0));
}
origin: oblac/jodd

@Test
void testRemoveMethodReturnedObject() {
  JsonArray obj = new JsonArray();
  obj.add("bar")
    .add(new JsonObject().put("name", "vert.x").put("count", 2))
    .add(new JsonArray().add(1.0).add(2.0));
  Object removed = obj.remove(0);
  assertTrue(removed instanceof String);
  removed = obj.remove(0);
  assertTrue(removed instanceof JsonObject);
  assertEquals(((JsonObject) removed).getString("name"), "vert.x");
  removed = obj.remove(0);
  assertTrue(removed instanceof JsonArray);
  assertEquals(((JsonArray) removed).getDouble(0), 1.0, 0.1);
}
origin: oblac/jodd

@Test
void testAddAllJsonArray() {
  jsonArray.add("bar");
  JsonArray arr = new JsonArray().add("foo").add(48);
  assertSame(jsonArray, jsonArray.addAll(arr));
  assertEquals(arr.getString(0), jsonArray.getString(1));
  assertEquals(arr.getInteger(1), jsonArray.getInteger(2));
}
jodd.jsonJsonArray<init>

Javadoc

Creates an empty instance.

Popular methods of JsonArray

  • getValue
    Returns the object value at position pos in the array.
  • list
    Returns the underlying list.
  • size
    Returns the number of values in this JSON array.
  • add
    Adds a binary value to the JSON array. JSON has no notion of binary so the binary will be base64 enc
  • addAll
    Appends all of the elements in the specified array to the end of this JSON array.
  • addNull
    Adds a null value to the JSON array.
  • arrayEquals
  • clear
    Removes all entries from the JSON array.
  • contains
    Returns true if given value exist.
  • equals
  • getBinary
    Returns the byte[] at position pos in the array. JSON itself has no notion of a binary, so this meth
  • getBoolean
    Returns the boolean at position pos in the array.
  • getBinary,
  • getBoolean,
  • getDouble,
  • getFloat,
  • getInteger,
  • getJsonArray,
  • getJsonObject,
  • getLong,
  • getString

Popular in Java

  • Making http requests using okhttp
  • startActivity (Activity)
  • getExternalFilesDir (Context)
  • onRequestPermissionsResult (Fragment)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now