-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10840 from playframework/undo-custom-json-parsing
- Loading branch information
Showing
5 changed files
with
202 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.utils; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
import java.util.Objects; | ||
|
||
// refs https://github.com/lagom/lagom/issues/3241 | ||
@JsonDeserialize(using = ChildDeserializer.class) | ||
public class Child { | ||
|
||
private final @NonNull Long updatedAt; | ||
private final @NonNull String updatedBy; | ||
|
||
@JsonCreator | ||
public Child(@NonNull Long updatedAt, @NonNull String updatedBy) { | ||
this.updatedAt = updatedAt; | ||
this.updatedBy = updatedBy; | ||
} | ||
|
||
public Long getUpdatedAt() { | ||
return updatedAt; | ||
} | ||
|
||
public String getUpdatedBy() { | ||
return updatedBy; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Child child = (Child) o; | ||
return updatedAt.equals(child.updatedAt) && updatedBy.equals(child.updatedBy); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(updatedAt, updatedBy); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Child{" + "updatedAt=" + updatedAt + ", updatedBy='" + updatedBy + '\'' + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.utils; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
import java.io.IOException; | ||
|
||
// refs https://github.com/lagom/lagom/issues/3241 | ||
@SuppressWarnings("WeakerAccess") | ||
public class ChildDeserializer extends StdDeserializer<Child> { | ||
|
||
public ChildDeserializer() { | ||
this(null); | ||
} | ||
|
||
public ChildDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public Child deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
JsonNode node = jp.readValueAsTree(); | ||
String updatedBy = node.get("updatedBy").asText(); | ||
Long updatedAt = node.get("updatedAt").asLong(); | ||
|
||
return new Child(updatedAt, updatedBy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.utils; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
import java.util.Objects; | ||
|
||
// refs https://github.com/lagom/lagom/issues/3241 | ||
public class Parent { | ||
|
||
private final @NonNull Long createdAt; | ||
private final Child child; | ||
private final @NonNull Long updatedAt; | ||
private final @NonNull String updatedBy; | ||
|
||
@JsonCreator | ||
public Parent( | ||
@JsonProperty("createdAt") @NonNull Long createdAt, | ||
@JsonProperty("child") Child child, | ||
@JsonProperty("updatedAt") @NonNull Long updatedAt, | ||
@JsonProperty("updatedBy") @NonNull String updatedBy) { | ||
this.createdAt = createdAt; | ||
this.child = child; | ||
this.updatedAt = updatedAt; | ||
this.updatedBy = updatedBy; | ||
} | ||
|
||
public Long getCreatedAt() { | ||
return createdAt; | ||
} | ||
|
||
public Child getChild() { | ||
return child; | ||
} | ||
|
||
public Long getUpdatedAt() { | ||
return updatedAt; | ||
} | ||
|
||
public String getUpdatedBy() { | ||
return updatedBy; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Parent parent = (Parent) o; | ||
return createdAt.equals(parent.createdAt) | ||
&& child.equals(parent.child) | ||
&& updatedAt.equals(parent.updatedAt) | ||
&& updatedBy.equals(parent.updatedBy); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(createdAt, child, updatedAt, updatedBy); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Parent{" | ||
+ "createdAt=" | ||
+ createdAt | ||
+ ", child=" | ||
+ child | ||
+ ", updatedAt=" | ||
+ updatedAt | ||
+ ", updatedBy='" | ||
+ updatedBy | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters