Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Exists method for check if Any object is empty
  • Loading branch information
maryo42 authored and maryo42 committed Mar 28, 2019
commit 9b9e94c81a092a071b4f4f8dc2c03a51c8ce5226
4 changes: 4 additions & 0 deletions src/main/java/com/jsoniter/any/Any.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ public Any mustBeValid() {
}
}

public boolean exists() {
return !(this instanceof NotFoundAny);
}

public Set keys() {
return EMPTY_KEYS;
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/jsoniter/any/TestNotFoundAny.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.jsoniter.any;

import com.jsoniter.JsonIterator;
import junit.framework.TestCase;

public class TestNotFoundAny extends TestCase {

public void test_exists() {
Any any = JsonIterator.deserialize("{\"field\": \"ABC\"}");
Any field = any.get("field");
Any otherField = any.get("otherField");
assertTrue(field.exists());
assertFalse(otherField.exists());
}

}