blob: fd5cdb52ff732d8ab4362c1a56e4a04fc56825a4 [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";
Simon Hunt09a32db2015-05-21 15:00:42 -070033 protected static final String DESC = "desc";
Simon Hunt41b943e2015-05-21 13:52:01 -070034
35 /**
36 * Returns a freshly minted object node.
37 *
38 * @return empty object node
39 */
40 protected static ObjectNode objectNode() {
41 return mapper.createObjectNode();
42 }
43
44 /**
45 * Returns a freshly minted array node.
46 *
47 * @return empty array node
48 */
49 protected static ArrayNode arrayNode() {
50 return mapper.createArrayNode();
51 }
52}