https://github.com/igapyon/simple-restapi
Simple REST API sample.
https://github.com/igapyon/simple-restapi
jackson json rest-api sample simple spring-boot spring-web
Last synced: about 2 months ago
JSON representation
Simple REST API sample.
- Host: GitHub
- URL: https://github.com/igapyon/simple-restapi
- Owner: igapyon
- License: apache-2.0
- Created: 2020-04-25T13:44:46.000Z (about 6 years ago)
- Default Branch: devel
- Last Pushed: 2020-05-19T13:11:18.000Z (about 6 years ago)
- Last Synced: 2025-02-24T11:18:47.539Z (over 1 year ago)
- Topics: jackson, json, rest-api, sample, simple, spring-boot, spring-web
- Language: Java
- Size: 162 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-restapi
シンプルな Spring Web + REST API + Jackson のサンプルです。
最初に想定 JSON データを作成します。
simplesample.json
```json
[
{
"id": 2,
"name": "hanako",
"age": 22
},
{
"id": 3,
"name": "takuya",
"age": 25
}
]
```
次に この JSONデータをもちいて Java Bean を生成します。
```sh
http://www.jsonschema2pojo.org/
```
これで出来あがった Java Bean をプロジェクトに含めて開発します。
あとは、出力したいデータを作って、ObjectMapper に文字列化させれば完成。
```java
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
String result = mapper.writeValueAsString(resultUsers);
```
このサンプルの起動方法は以下の通り。
```sh
mvn spring-boot:run
```
サンプル画面への到達方法は以下。
```
http://localhost:8080/api/simpleget/id5535
```
このサンプルの実行結果
```json
[
{
"id" : 2,
"name" : "hanako",
"age" : 22
},
{
"id" : 3,
"name" : "takuya",
"age" : 25
}
]
```