Spring Rest - newgeekorder/TechWiki GitHub Wiki

Basic Json Rest

package com.rabobank;

import com.jsoniter.output.JsonStream;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MockCollibra {
    @GetMapping(path="/export", produces=MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> sayHello()
    {
        //Get data from service layer into entityList.
        Map<String, String> map = new HashMap<>();
        map.put("hello", "world");
        String jsonStringFromObject = JsonStream.serialize(map);
        return new ResponseEntity<Object>(jsonStringFromObject, HttpStatus.OK);
    }
}

and the boiler plate app

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {
//    @Autowired
//    MockCollibra mockCollibra;

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

}
⚠️ **GitHub.com Fallback** ⚠️