-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract Serializer's JsonMapper into an explicit adapter class
- Loading branch information
1 parent
7e2a8fb
commit dc70b35
Showing
3 changed files
with
26 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package edu.byu.cs.server; | ||
|
||
import edu.byu.cs.util.Serializer; | ||
import io.javalin.json.JsonMapper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* A Serializer class adapter which implements Javalin's JsonMapper interface. | ||
* Allows Javalin's built-in serialization to use Serializer. | ||
*/ | ||
public class SerializerAdapter implements JsonMapper { | ||
@NotNull | ||
@Override | ||
public <T> T fromJsonString(@NotNull String json, @NotNull Type targetType) { | ||
return Serializer.deserialize(json, targetType); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String toJsonString(@NotNull Object obj, @NotNull Type type) { | ||
return Serializer.serialize(obj, type); | ||
} | ||
} |
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