1

Rename SerializationService to JsonService

Co-authored-by: Christoph <tobi@urpost.de>
This commit is contained in:
Christoph
2020-03-18 21:46:14 +01:00
parent e1a630ae1a
commit 08717611d5
3 changed files with 7 additions and 7 deletions

View File

@ -0,0 +1,38 @@
package mops.gruppen2.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import mops.gruppen2.domain.event.Event;
import org.springframework.stereotype.Service;
/**
* Übersetzt JSON-Event-Payloads zu Java-Event-Repräsentationen und zurück.
*/
@Service
public class JsonService {
/**
* Übersetzt mithilfe der Jackson-Library eine Java-Event-Repräsentation zu einem JSON-Event-Payload.
*
* @param event Java-Event-Repräsentation
* @return JSON-Event-Payload als String
* @throws JsonProcessingException
*/
public String serializeEvent(Event event) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(event);
}
/**
* Übersetzt mithilfe der Jackson-Library einen JSON-Event-Payload zu einer Java-Event-Repräsentation.
*
* @param json JSON-Event-Payload als String
* @return Java-Event-Repräsentation
* @throws JsonProcessingException
*/
public Event deserializeEvent(String json) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, Event.class);
}
}