blob: 191e0071b6f20c5a1ef53b7567ede3ec618a789f [file] [log] [blame]
Simon Hunt41b943e2015-05-21 13:52:01 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt41b943e2015-05-21 13:52:01 -07003 *
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
18package org.onosproject.cord.gui.model;
19
20import com.fasterxml.jackson.databind.ObjectMapper;
21import com.fasterxml.jackson.databind.node.ArrayNode;
22import com.fasterxml.jackson.databind.node.ObjectNode;
23
24/**
25 * Base class for factories that convert objects to JSON.
26 */
27public abstract class JsonFactory {
28
Simon Hunt6c2555b2015-05-21 18:17:56 -070029 private static final ObjectMapper MAPPER = new ObjectMapper();
Simon Hunt41b943e2015-05-21 13:52:01 -070030
31 protected static final String ID = "id";
32 protected static final String NAME = "name";
Simon Hunt09a32db2015-05-21 15:00:42 -070033 protected static final String DESC = "desc";
Simon Hunt0d94f062015-06-04 10:56:03 -070034 protected static final String ICON_ID = "icon_id";
Simon Hunt41b943e2015-05-21 13:52:01 -070035
36 /**
37 * Returns a freshly minted object node.
38 *
39 * @return empty object node
40 */
41 protected static ObjectNode objectNode() {
Simon Hunt6c2555b2015-05-21 18:17:56 -070042 return MAPPER.createObjectNode();
Simon Hunt41b943e2015-05-21 13:52:01 -070043 }
44
45 /**
46 * Returns a freshly minted array node.
47 *
48 * @return empty array node
49 */
50 protected static ArrayNode arrayNode() {
Simon Hunt6c2555b2015-05-21 18:17:56 -070051 return MAPPER.createArrayNode();
Simon Hunt41b943e2015-05-21 13:52:01 -070052 }
53}