Skip to content

Instantly share code, notes, and snippets.

@itzg
Created July 15, 2021 15:15
Show Gist options
  • Save itzg/ac5512c251a5ea63935664883feda826 to your computer and use it in GitHub Desktop.
Save itzg/ac5512c251a5ea63935664883feda826 to your computer and use it in GitHub Desktop.
Trying out JsonProperty to customize enum serialized value
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