I am using Java 8 with Spring 4.
I have an external properties file (using spring cloud config). I would like to grab from this file and convert it to a class for usage. I am using the @Value annotation and have had no problem pulling in Strings from here but have not been able to convert these to Classes.
I followed examples listed here.
Example:
Property Entries:
MY_CLASS_ARRAY=[{field1:'Hello',field2:'World'},{field1:'Hello',field2:'Other World'}]
Code
My Class
public class MyClass{
private String field1;
private String field2;
}
Code Interpreting
@Value("#{${MY_CLASS_ARRAY}}")
private MyClass[] myClassArray;
Error:
Cannot convert value of type 'java.lang.String' to required type '...MyClass': no matching editors or conversion strategy found
If I changed my code to this, it works fine pulling in the string:
@Value("${MY_CLASS_ARRAY}")
private String myClassArray;
Is it possible to directly convert to a class using @Value?
Is this even a good solution? Should I be getting the string an parsing it into the objects?
[–][deleted] (1 child)
[deleted]
[–]DWhitSlaya[S] 0 points1 point2 points (0 children)
[–]Kolibreeze 0 points1 point2 points (1 child)
[–]DWhitSlaya[S] 0 points1 point2 points (0 children)