blob: 5592b51e3b39a0431a01c38b7d9cddd731f1c640 [file] [log] [blame]
Simon Hunt41b943e2015-05-21 13:52:01 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
29 private static final ObjectMapper mapper = new ObjectMapper();
30
31 protected static final String ID = "id";
32 protected static final String NAME = "name";
33
34 /**
35 * Returns a freshly minted object node.
36 *
37 * @return empty object node
38 */
39 protected static ObjectNode objectNode() {
40 return mapper.createObjectNode();
41 }
42
43 /**
44 * Returns a freshly minted array node.
45 *
46 * @return empty array node
47 */
48 protected static ArrayNode arrayNode() {
49 return mapper.createArrayNode();
50 }
51}