Created
July 15, 2021 15:15
-
-
Save itzg/ac5512c251a5ea63935664883feda826 to your computer and use it in GitHub Desktop.
Trying out JsonProperty to customize enum serialized value
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
package testing; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.junit.jupiter.api.Test; | |
import static org.assertj.core.api.Assertions.assertThat; | |
class SerializeEnumTest { | |
public enum Type { | |
@JsonProperty("internal") | |
INTERNAL, | |
@JsonProperty("external") | |
EXTERNAL | |
} | |
@Test | |
void usesJsonProperty() throws JsonProcessingException { | |
final String result = new ObjectMapper().writeValueAsString(Type.INTERNAL); | |
assertThat(result).isEqualTo("\"internal\""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment