blob: 83fe4182fee640e7630aa53d37e2242f10db303b [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
lishuai91d986c2015-07-28 09:45:20 +08003 *
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 */
16package org.onosproject.ovsdb.rfc.notation.json;
17
lishuai91d986c2015-07-28 09:45:20 +080018import com.fasterxml.jackson.core.JsonGenerator;
lishuai91d986c2015-07-28 09:45:20 +080019import com.fasterxml.jackson.databind.JsonSerializer;
20import com.fasterxml.jackson.databind.SerializerProvider;
Jonathan Hart51539b82015-10-29 09:53:04 -070021import org.onosproject.ovsdb.rfc.notation.Uuid;
22
23import java.io.IOException;
lishuai91d986c2015-07-28 09:45:20 +080024
25/**
26 * UUID Serializer.
27 */
Jonathan Hart51539b82015-10-29 09:53:04 -070028public class UuidSerializer extends JsonSerializer<Uuid> {
lishuai91d986c2015-07-28 09:45:20 +080029 @Override
Jonathan Hart51539b82015-10-29 09:53:04 -070030 public void serialize(Uuid value, JsonGenerator generator,
lishuai2f197432015-07-31 16:27:58 +080031 SerializerProvider provider) throws IOException {
lishuai91d986c2015-07-28 09:45:20 +080032 generator.writeStartArray();
lishuai2f197432015-07-31 16:27:58 +080033 String reg = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
34 if (value.value().matches(reg)) {
lishuai91d986c2015-07-28 09:45:20 +080035 generator.writeString("uuid");
lishuai2f197432015-07-31 16:27:58 +080036 } else {
lishuai91d986c2015-07-28 09:45:20 +080037 generator.writeString("named-uuid");
38 }
39 generator.writeString(value.value());
40 generator.writeEndArray();
41 }
42}