| Conditions | 2 |
| Total Lines | 26 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package de.kleiner3.lasertag.lasertaggame.teammanagement.serialize; |
||
| 19 | public static GsonBuilder getSerializer() { |
||
| 20 | // Create builder |
||
| 21 | var gsonBuilder = new GsonBuilder(); |
||
| 22 | |||
| 23 | // Create serializer for TeamDto |
||
| 24 | var serializer = new JsonSerializer<TeamDto>() { |
||
| 25 | @Override |
||
| 26 | public JsonElement serialize(TeamDto teamDto, Type type, JsonSerializationContext jsonSerializationContext) { |
||
| 27 | var jsonObject = new JsonObject(); |
||
| 28 | |||
| 29 | // Add RGB |
||
| 30 | jsonObject.addProperty("red", teamDto.color().r()); |
||
| 31 | jsonObject.addProperty("green", teamDto.color().g()); |
||
| 32 | jsonObject.addProperty("blue", teamDto.color().b()); |
||
| 33 | |||
| 34 | // Add spawnpoint block |
||
| 35 | jsonObject.addProperty("spawnpointBlock", Registry.BLOCK.getId(teamDto.spawnpointBlock()).toString()); |
||
| 36 | |||
| 37 | return jsonObject; |
||
| 38 | } |
||
| 39 | }; |
||
| 40 | |||
| 41 | // Register serializer for TeamDto |
||
| 42 | gsonBuilder.registerTypeAdapter(TeamDto.class, serializer); |
||
| 43 | |||
| 44 | return gsonBuilder; |
||
| 45 | } |
||
| 47 |