Skip to content

Commit

Permalink
Deprecate ObjectDocument.setNull for set(null) call
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikat committed Sep 9, 2017
1 parent 2b413df commit 00ce513
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/main/java/moe/banana/jsonapi2/ObjectDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

public class ObjectDocument<DATA extends ResourceIdentifier> extends Document<DATA> {

DATA data = null;

boolean isExplicitNull;
private DATA data = null;
private boolean nullFlag;

public ObjectDocument() {
}
Expand All @@ -21,18 +20,20 @@ public void set(DATA data) {
data.setDocument(this);
}
this.data = data;
this.nullFlag = data == null;
}

public DATA get() {
return data;
}

@Deprecated
public void setNull(boolean isNull) {
isExplicitNull = isNull;
nullFlag = isNull;
}

public boolean isNull() {
return isExplicitNull;
return nullFlag;
}

@Override
Expand All @@ -43,15 +44,15 @@ public boolean equals(Object o) {

ObjectDocument<?> that = (ObjectDocument<?>) o;

if (isExplicitNull != that.isExplicitNull) return false;
if (nullFlag != that.nullFlag) return false;
return data.equals(that.data);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + data.hashCode();
result = 31 * result + (isExplicitNull ? 1 : 0);
result = 31 * result + (nullFlag ? 1 : 0);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Document<DATA> fromJson(JsonReader reader) throws IOException {
} else if (reader.peek() == JsonReader.Token.NULL) {
reader.nextNull();
document = document.asObjectDocument();
((ObjectDocument<DATA>) document).setNull(true);
((ObjectDocument<DATA>) document).set(null);
} else {
reader.skipValue();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/moe/banana/jsonapi2/DocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void deserialize_array_to_array_typed_document() throws Exception {
public void serialize_null() {
ObjectDocument document = new ObjectDocument();
assertThat(getDocumentAdapter(ResourceIdentifier.class).toJson(document), equalTo("{}"));
document.setNull(true);
document.set(null);
assertThat(getDocumentAdapter(ResourceIdentifier.class).toJson(document), equalTo("{\"data\":null}"));
}

Expand Down

0 comments on commit 00ce513

Please sign in to comment.