update verigraph
[parser.git] / verigraph / src / it / polito / verigraph / serializer / CustomMapSerializer.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Politecnico di Torino and others.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Apache License, Version 2.0
6  * which accompanies this distribution, and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *******************************************************************************/
9 package it.polito.verigraph.serializer;
10
11 import java.io.IOException;
12 import java.util.Map;
13 import com.fasterxml.jackson.core.JsonGenerator;
14 import com.fasterxml.jackson.databind.JsonSerializer;
15 import com.fasterxml.jackson.databind.SerializerProvider;
16 import it.polito.verigraph.exception.InternalServerErrorException;
17
18 public class CustomMapSerializer extends JsonSerializer<Map<?, ?>> {
19     @Override
20     public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) {
21         try {
22             jgen.writeObject(value.values());
23         } catch (IOException e) {
24             throw new InternalServerErrorException("I/O error serializing a map: " + e.getMessage());
25         }
26     }
27 }