[LIB-13] Tournament and game formats for JSON parsing
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / json / format / JSONFormatBuilder.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.scanner.json.format;
18
19 import com.google.gson.Gson;
20 import com.google.gson.GsonBuilder;
21
22 import org.hedgecode.chess.scanner.format.ArenaFormat;
23 import org.hedgecode.chess.scanner.format.FormatBuilder;
24 import org.hedgecode.chess.scanner.format.GameFormat;
25 import org.hedgecode.chess.scanner.format.TournamentFormat;
26
27 /**
28  * JSONFormatBuilder
29  *
30  * @author Dmitry Samoshin aka gotty
31  */
32 public class JSONFormatBuilder implements FormatBuilder {
33
34     private static final Gson GSON = new GsonBuilder().create();
35
36     @Override
37     public GameFormat buildGame(String jsonGame) {
38         return GSON.fromJson(
39                 jsonGame,
40                 JSONGameFormat.class
41             );
42     }
43
44     @Override
45     public TournamentFormat buildTournament(String jsonTournament) {
46         return GSON.fromJson(
47                 jsonTournament,
48                 JSONTournamentFormat.class
49         );
50     }
51
52     @Override
53     public ArenaFormat buildArena(String jsonArena) {
54         return GSON.fromJson(
55                 jsonArena,
56                 JSONArenaFormat.class
57         );
58     }
59
60 }