If you wanna use your own protocol, you may just return String from method of Spring Controller. I wrote for you a little example. I used "jackson-jaxrs-json-provider) for mapping. You may create you own function for converting your beans. It's very easy.
For example you have a class:
public class MyBean {
private String name;
private String value;
private List<MyBean> beanList = new ArrayList<>();
public MyBean(String name, String value, MyBean previous) {
this.name = name;
this.value = value;
if (previous != null)
this.beanList.add(previous);
}
//getters & setters
}
The you create simple function for convertation:
public static String convertToMyJson(Object value) {
try {
ObjectMapper mapper = new ObjectMapper();
String resultList = mapper.writeValueAsString(value);
resultList = "{" + resultList.replaceAll("(^\\[)|(\\]$)", "") + "}";
System.out.println(resultList);
}
catch(Exception e) {
e.printStackTrace(System.err);
}
return "";
}
And in the end, you just return simple string in Spring MVC Controller:
@RequestMapping(path = "get-bean", method = RequestMethod.GET)
public String getBean() {
MyBean bean1 = new MyBean("name1", "11", null);
MyBean bean2 = new MyBean("name2", "22", bean1);
List<MyBean> beanList = new ArrayList<>();
beanList.add(bean1);
beanList.add(bean2);
return convertToMyJson(beanList);
}
And you'll get something like that:
{
{
"name":"name1",
"value":"11",
"beanList":[
]
},
{
"name":"name2",
"value":"22",
"beanList":[
{
"name":"name1",
"value":"11",
"beanList":[
]
}
]
}
}