Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package org.onosproject.cord.gui.model; |
| 19 | |
| 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 21 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 23 | |
| 24 | /** |
| 25 | * Base class for factories that convert objects to JSON. |
| 26 | */ |
| 27 | public abstract class JsonFactory { |
| 28 | |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 29 | private static final ObjectMapper MAPPER = new ObjectMapper(); |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 30 | |
| 31 | protected static final String ID = "id"; |
| 32 | protected static final String NAME = "name"; |
Simon Hunt | 09a32db | 2015-05-21 15:00:42 -0700 | [diff] [blame] | 33 | protected static final String DESC = "desc"; |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Returns a freshly minted object node. |
| 37 | * |
| 38 | * @return empty object node |
| 39 | */ |
| 40 | protected static ObjectNode objectNode() { |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 41 | return MAPPER.createObjectNode(); |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns a freshly minted array node. |
| 46 | * |
| 47 | * @return empty array node |
| 48 | */ |
| 49 | protected static ArrayNode arrayNode() { |
Simon Hunt | 6c2555b | 2015-05-21 18:17:56 -0700 | [diff] [blame] | 50 | return MAPPER.createArrayNode(); |
Simon Hunt | 41b943e | 2015-05-21 13:52:01 -0700 | [diff] [blame] | 51 | } |
| 52 | } |