Skip to content

Package: JsonSerializationFixed

JsonSerializationFixed

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2018, 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.app.api.resources.v1.resources.marker;
14:
15: import org.eclipse.kapua.app.api.resources.v1.resources.DataMessages;
16: import org.eclipse.kapua.app.api.core.model.data.JsonDatastoreMessage;
17: import org.eclipse.kapua.app.api.core.model.data.JsonKapuaDataMessage;
18: import org.eclipse.kapua.app.api.core.model.device.management.JsonGenericRequestMessage;
19: import org.eclipse.kapua.app.api.core.model.device.management.JsonGenericResponseMessage;
20: import org.eclipse.kapua.message.device.data.KapuaDataMessage;
21: import org.eclipse.kapua.service.datastore.model.DatastoreMessage;
22: import org.eclipse.kapua.service.device.management.request.message.request.GenericRequestMessage;
23: import org.eclipse.kapua.service.device.management.request.message.response.GenericResponseMessage;
24:
25: /**
26: * This is a marker interface to mark JAX-RS resources which do not map to any actual Kapua resource but they wrap existing resources.
27: * <p>
28: * Any JAX-RS resource marked with this {@code interface} that acts as a bridge for the JSON serialization of generic request objects.
29: * <p>
30: * The {@link org.eclipse.kapua.message.KapuaPayload} is marshalled with the following format:
31: * <pre>
32: * <payload xsi:type="kapuaDataPayload">
33: * <metrics>
34: * <metric>
35: * <valueType>float<valueType/>
36: * <value>5.0<value/>
37: * <name>temperatureExternal<name/>
38: * <metric/>
39: * <metric>
40: * <valueType>float<valueType/>
41: * <value>19.25<value/>
42: * <name>temperatureInternal<name/>
43: * <metric/>
44: * <metric>
45: * <valueType>float<valueType/>
46: * <value>30.00<value/>
47: * <name>temperatureExhaust<name/>
48: * <metric/>
49: * <metric>
50: * <valueType>integer<valueType/>
51: * <value>-1422687692<value/>
52: * <name>errorCode<name/>
53: * <metric/>
54: * <metrics/>
55: * <body>YXNk</body>
56: * </payload>
57: * </pre>
58: * <p>
59: * But the JSON has the following format:
60: * <pre>
61: * "payload": {
62: * "metrics": {
63: * "metric": [
64: * {
65: * "valueType" : "float",
66: * "value" : "5.0",
67: * "name" : "temperatureExternal"
68: * }, {
69: * "valueType" : "float",
70: * "value" : "19.25",
71: * "name" : "temperatureInternal"
72: * }, {
73: * "valueType" : "float",
74: * "value" : "30.0",
75: * "name" : "temperatureExhaust"
76: * }, {
77: * "valueType" : "integer",
78: * "value" : "-1422687692",
79: * "name" : "errorCode"
80: * }
81: * ]
82: * },
83: * "body": "YXNk"
84: * }
85: * </pre>
86: * For some reasons in JSON format "metrics" is an object with "metric" array as a field.
87: * <p>
88: * Since we weren't able to fina JAXB mapping configuration to allow correct formatting of both XML and JSON,
89: * this "bridge" class is introduced to allow a translation of the {@link org.eclipse.kapua.message.KapuaPayload}.
90: * <p>
91: * This resources then maps to the {@link DataMessages} class, just translating:
92: * <ul>
93: * <li>{@link KapuaDataMessage} to {@link JsonKapuaDataMessage}</li>
94: * <li>{@link DatastoreMessage} to {@link JsonDatastoreMessage}</li>
95: * <li>{@link GenericRequestMessage} to {@link JsonGenericRequestMessage}</li>
96: * <li>{@link GenericResponseMessage} to {@link JsonGenericResponseMessage}</li>
97: * </ul>
98: * Final JSON output is:
99: * <pre>
100: * "payload": {
101: * "metrics": [
102: * {
103: * "valueType" : "float",
104: * "value" : "5.0",
105: * "name" : "temperatureExternal"
106: * }, {
107: * "valueType" : "float",
108: * "value" : "19.25",
109: * "name" : "temperatureInternal"
110: * }, {
111: * "valueType" : "float",
112: * "value" : "30.0",
113: * "name" : "temperatureExhaust"
114: * }, {
115: * "valueType" : "integer",
116: * "value" : "-1422687692",
117: * "name" : "errorCode"
118: * }
119: * ],
120: * "body": "YXNk"
121: * }
122: * </pre>
123: */
124: public interface JsonSerializationFixed {
125: }