Affects: 5.2.0.RELEASE


I would like to use the Spring annotation @Value to map a json-format string property to a object of custom class.

For example, I want to do this:

    @Value("${some.special.book}")
    private Book book;

where the property file says:

some.special.book={"title":"Animal Farm","id":5566}

Then I have to add a PropertyEditor that can handle json parsing into CustomEditorConfigurer.

I saw that there are plenty off-the-shelf PropertyEditor in https://github.com/spring-projects/spring-framework/tree/master/spring-beans/src/main/java/org/springframework/beans/propertyeditors, and I wonder if we can add a PropertyEditor that can parse json-format string and map to a custom object (maybe with Jackson library). Thank you.

Comment From: sbrannen

Thanks for the suggestion. That's certainly an interesting use case; however, for PropertyEditor support within the core Spring Framework we prefer not to incorporate anything as complex as marshaling/unmarshaling, JSON serialization/deserialization, etc.

In light of that I am closing this issue.

p.s. Although not quite the same as what you're asking for, if you're using Spring Boot you might find Boot's SPRING_APPLICATION_JSON support useful.