11package org .skyscreamer .jsonassert ;
22
3+ import java .util .ArrayList ;
4+ import java .util .Collections ;
5+ import java .util .List ;
6+
37/**
48 * Bean for holding results from JSONCompare.
59 */
@@ -9,6 +13,7 @@ public class JSONCompareResult {
913 private String _field ;
1014 private Object _expected ;
1115 private Object _actual ;
16+ private final List <FieldComparisonFailure > _fieldFailures = new ArrayList <FieldComparisonFailure >();
1217
1318 /**
1419 * Default constructor.
@@ -46,12 +51,20 @@ public String getMessage() {
4651 return _message ;
4752 }
4853
54+ /**
55+ * Get the list of failures on field comparisons
56+ */
57+ public List <FieldComparisonFailure > getFieldFailures () {
58+ return Collections .unmodifiableList (_fieldFailures );
59+ }
60+
4961 /**
5062 * Actual field value
5163 *
5264 * @return a {@code JSONObject}, {@code JSONArray} or other {@code Object}
5365 * instance, or {@code null} if the comparison did not fail on a
5466 * particular field
67+ * @deprecated Superseded by {@link #getFieldFailures()}
5568 */
5669 public Object getActual () {
5770 return _actual ;
@@ -63,23 +76,25 @@ public Object getActual() {
6376 * @return a {@code JSONObject}, {@code JSONArray} or other {@code Object}
6477 * instance, or {@code null} if the comparison did not fail on a
6578 * particular field
79+ * @deprecated Superseded by {@link #getFieldFailures()}
6680 */
6781 public Object getExpected () {
6882 return _expected ;
6983 }
7084
7185 /**
72- * Check if comparison failed on a particular field
86+ * Check if comparison failed on any particular fields
7387 */
7488 public boolean isFailureOnField () {
75- return _field != null ;
89+ return ! _fieldFailures . isEmpty () ;
7690 }
7791
7892 /**
7993 * Dot-separated path the the field that failed comparison
8094 *
8195 * @return a {@code String} instance, or {@code null} if the comparison did
8296 * not fail on a particular field
97+ * @deprecated Superseded by {@link #getFieldFailures()}
8398 */
8499 public String getField () {
85100 return _field ;
@@ -102,6 +117,7 @@ protected void fail(String message) {
102117 * @param actual Actual result
103118 */
104119 protected JSONCompareResult fail (String field , Object expected , Object actual ) {
120+ _fieldFailures .add (new FieldComparisonFailure (field , expected , actual ));
105121 this ._field = field ;
106122 this ._expected = expected ;
107123 this ._actual = actual ;
0 commit comments