Skip to content

Package: JsonServiceEventMarshaler

JsonServiceEventMarshaler

nameinstructionbranchcomplexitylinemethod
JsonServiceEventMarshaler()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getContentType()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
marshal(ServiceEvent)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
unmarshal(String)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.commons.event;
14:
15: import org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.commons.util.xml.XmlUtil;
17: import org.eclipse.kapua.event.ServiceEvent;
18: import org.eclipse.kapua.event.ServiceEventBusException;
19: import org.xml.sax.SAXException;
20:
21: import javax.xml.bind.JAXBException;
22:
23: /**
24: * Json {@link ServiceEventMarshaler} implementation.
25: *
26: * @since 1.0.0
27: */
28: public class JsonServiceEventMarshaler implements ServiceEventMarshaler {
29:
30: public static final String CONTENT_TYPE_JSON = "application/json";
31:
32: @Override
33: public String getContentType() {
34: return CONTENT_TYPE_JSON;
35: }
36:
37: @Override
38: public ServiceEvent unmarshal(String message) throws KapuaException {
39: try {
40: return XmlUtil.unmarshalJson(message, ServiceEvent.class, null);
41: } catch (JAXBException | SAXException e) {
42: throw new ServiceEventBusException(e);
43: }
44: }
45:
46: @Override
47: public String marshal(ServiceEvent kapuaEvent) throws ServiceEventBusException {
48: try {
49: return XmlUtil.marshalJson(kapuaEvent);
50: } catch (JAXBException e) {
51: throw new ServiceEventBusException(e);
52: }
53: }
54: }