blob: ed02c3e3b3aea63820fc3644a1daeb3bfee72cff [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -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 */
Ayaka Koshibe08e457a2015-06-25 17:11:54 -070016package org.onosproject.store.serializers;
17
18import org.onosproject.net.DefaultAnnotations;
19
20import com.esotericsoftware.kryo.Kryo;
21import com.esotericsoftware.kryo.Serializer;
22import com.esotericsoftware.kryo.io.Input;
23import com.esotericsoftware.kryo.io.Output;
24
25import java.util.HashMap;
26
27public class AnnotationsSerializer extends Serializer<DefaultAnnotations> {
28
29 public AnnotationsSerializer() {
30 super(false, true);
31 }
32
33 @Override
34 public void write(Kryo kryo, Output output, DefaultAnnotations object) {
35 kryo.writeObject(output, object.asMap());
36 }
37
38 @Override
39 public DefaultAnnotations read(Kryo kryo, Input input, Class<DefaultAnnotations> type) {
40 DefaultAnnotations.Builder b = DefaultAnnotations.builder();
41 HashMap<String, String> map = kryo.readObject(input, HashMap.class);
42 map.forEach((k, v) -> b.set(k, v));
43
44 return b.build();
45 }
46
47}