-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
67 additions
and
9 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
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
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,31 @@ | ||
package io.openliberty.sample.application; | ||
|
||
import jakarta.json.bind.annotation.JsonbTypeDeserializer; | ||
|
||
@JsonbTypeDeserializer(RankDeserializer.class) | ||
public enum Rank { | ||
CAPTAIN("Captain"), | ||
OFFICER("Officer"), | ||
ENGINEER("Engineer"); | ||
|
||
private final String formatted; | ||
|
||
Rank(String s) { | ||
formatted = s; | ||
} | ||
|
||
public static Rank fromString(String s) { | ||
for (Rank r : values()) { | ||
if (r.formatted.equals(s)) { | ||
return r; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return formatted; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/openliberty/sample/application/RankDeserializer.java
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,18 @@ | ||
package io.openliberty.sample.application; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import jakarta.json.bind.serializer.DeserializationContext; | ||
import jakarta.json.bind.serializer.JsonbDeserializer; | ||
import jakarta.json.stream.JsonParser; | ||
|
||
|
||
public class RankDeserializer implements JsonbDeserializer<Rank> { | ||
|
||
@Override | ||
public Rank deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { | ||
String name = parser.getValue().toString().replaceAll("\"", ""); //TODO update app so we don't need to remove "" | ||
return Rank.fromString(name); | ||
} | ||
|
||
} |
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