Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityModel enum map key not support #1990

Open
xiaoyao9184 opened this issue Jul 14, 2023 · 0 comments
Open

EntityModel enum map key not support #1990

xiaoyao9184 opened this issue Jul 14, 2023 · 0 comments

Comments

@xiaoyao9184
Copy link

spring-hateoas 1.1.2

code like this

    public enum EnumKey {
        K1,
        K2
    }

    @GetMapping("/test")
    @ResponseBody
    public ResponseEntity<EntityModel<Map<EnumKey,String>>> test() {
        Map<EnumKey,String> map = new HashMap<>();
        map.put(EnumKey.K1,"1");
        map.put(EnumKey.K2,"2");

        return ok(EntityModel.of(map));
    }

error

Could not write JSON: ****Controller$EnumKey incompatible with java.lang.String; nested exception is com.fasterxml.jackson.databind.JsonMappingException: ****Controller$EnumKey incompatible with java.lang.String (through reference chain: org.springframework.hateoas.EntityModel["[anySetter]"]->java.util.HashMap["K2"])

i think hateoas use @JsonAnyGetter and com.fasterxml.jackson.databind.ser.AnyGetterWriter use string key MapSerializer

@Nullable
@JsonAnyGetter
@SuppressWarnings("unchecked")
private Map<String, Object> getMapContent() {
return Map.class.isInstance(content) ? (Map<String, Object>) content : null;
}

already use this added enum key serializer

still doesn't work, what is the correct way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant