Community day coding contest
Write a program that instantiates objects. Implement the following interface: eu.javaca.playground.Instantiable:
public String instantiate(Class any, Target target);
The "instantiate" method can take "any" class type and returns a serialized version of an instance of class "any" (as a JSON string, controlled by the target which is an Enum value "JSON").
Your solution will be evaluated based on the following criteria:
-
Completeness. Firstly, it has to work, but the richer your solution is, the better. Think of various collections, data types, inheritance, generics, etc
-
Corner case handling. Eg: one of the fields is a List. The instantiated solution contains at least one example of each sub-types of Animal (let’s say, Dog, Cat, Koala) in the serialized list. Support for parameterized classes, JAXBElement (for xml and so on)
-
Design. How elegant your solution is. How easy it is to read, extend, understand.
Example:
AboutPerson {
String name;
Integer age;
List<Hobbies> hobbies;
Book favouriteBook;
Workplace<Person> workplace;
}
Possible JSON result:
{
"name":"zmiusdlm mamdfu",
"age": 21,
"hobbies": [{
"type": "WATER_SPORT",
"proficiencyLevel": 4,
"timePracticing": 10,
"name": "Swimming",
"requiresSuit": true
}, {
"name":"Chess",
"eloRating": 1560
}],
"favouriteBook": {"name": "Lumea Sofiei", "ISBN": "308283402880"},
"workplace": null
}
Stretch goals:
- Implement XML target.
- Take into account validation annotations.
The solution is not just didactic but has very good use-cases. Eg:
A library that can generate examples based on POJOs or DTOs that does not just default to empty arrays or default values.
Generating XML testing files for SOAP services
Generating JSON files for REST services