GNPy client refactor
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / gnpy / consumer / JsonConfigurator.java
1 /*
2  * Copyright © 2021 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.pce.gnpy.consumer;
9
10 import com.fasterxml.jackson.annotation.JsonInclude;
11 import com.fasterxml.jackson.databind.DeserializationFeature;
12 import com.fasterxml.jackson.databind.ObjectMapper;
13 import com.fasterxml.jackson.databind.SerializationFeature;
14 import javax.ws.rs.ext.ContextResolver;
15 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
16 import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.GnpyApi;
17 import org.opendaylight.yang.gen.v1.gnpy.path.rev200909.Result;
18
19 public class JsonConfigurator implements ContextResolver<ObjectMapper> {
20
21     private final ObjectMapper mapper;
22
23     public JsonConfigurator(JsonStringConverter<GnpyApi> gnpyApiConverter,
24             JsonStringConverter<Result> resultConverter) {
25         mapper = new ObjectMapper();
26         mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
27         mapper.enable(SerializationFeature.INDENT_OUTPUT);
28         mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
29         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
30         mapper.registerModule(new GnpyApiModule(gnpyApiConverter, resultConverter));
31     }
32
33     @Override
34     public ObjectMapper getContext(Class<?> type) {
35         return mapper;
36     }
37
38 }