* VID
* ================================================================================
* Copyright (C) 2018 - 2019 Nokia. All rights reserved.
+ * Modifications Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.vid.client;
-import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.onap.vid.client.UnirestPatchKt.patched;
+import static org.onap.vid.utils.KotlinUtilsKt.JOSHWORKS_JACKSON_OBJECT_MAPPER;
import com.att.eelf.configuration.EELFLogger;
import io.joshworks.restclient.http.HttpResponse;
}
private ObjectMapper defaultObjectMapper() {
- com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
-
- return new ObjectMapper() {
- @Override
- public <T> T readValue(String value, Class<T> aClass) {
- try {
- return isEmpty(value) ? null : objectMapper.readValue(value, aClass);
- } catch (IOException e) {
- throw new SyncRestClientException("IOException while reading value", e);
- }
- }
-
- @Override
- public String writeValue(Object value) {
- try {
- return objectMapper.writeValueAsString(value);
- } catch (IOException e) {
- throw new SyncRestClientException("IOException while writing value", e);
- }
- }
- };
+ return JOSHWORKS_JACKSON_OBJECT_MAPPER;
}
private CloseableHttpClient defaultHttpClient() {
package org.onap.vid.controller;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.module.kotlin.KotlinModule;
import io.joshworks.restclient.http.mapper.ObjectMapper;
import java.io.File;
-import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletContext;
import org.onap.vid.services.ChangeManagementService;
import org.onap.vid.services.PombaService;
import org.onap.vid.services.PombaServiceImpl;
+import org.onap.vid.utils.JoshworksJacksonObjectMapper;
import org.onap.vid.utils.Logging;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
}
@Bean
- public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
- return new ObjectMapper() {
-
- @Override
- public <T> T readValue(String s, Class<T> aClass) {
- try {
- return isEmpty(s) ? null : objectMapper.readValue(s, aClass);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public String writeValue(Object o) {
- try {
- return objectMapper.writeValueAsString(o);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
- };
-
+ public ObjectMapper unirestFasterxmlObjectMapper() {
+ return new JoshworksJacksonObjectMapper();
}
@Bean
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
+import org.apache.commons.lang3.StringUtils.isEmpty
inline fun <reified E: Enum<E>> getEnumFromMapOfStrings(map: Map<String, Any>, key:String, defaultValue:E): E {
return java.lang.Enum.valueOf(E::class.java, (map.getOrDefault(key, defaultValue.name) as String))
}
@JvmField val JACKSON_OBJECT_MAPPER: ObjectMapper = jacksonObjectMapper()
+
+class JoshworksJacksonObjectMapper: io.joshworks.restclient.http.mapper.ObjectMapper {
+ override fun writeValue(value: Any?): String? {
+ return JACKSON_OBJECT_MAPPER.writeValueAsString(value)
+ }
+
+ override fun <T : Any?> readValue(value: String?, valueType: Class<T>?): T? {
+ return if (isEmpty(value)) null else JACKSON_OBJECT_MAPPER.readValue(value, valueType)
+ }
+}
+
+@JvmField val JOSHWORKS_JACKSON_OBJECT_MAPPER:
+ io.joshworks.restclient.http.mapper.ObjectMapper = JoshworksJacksonObjectMapper()
* VID
* ================================================================================
* Copyright (C) 2018 - 2019 Nokia Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.mockito.Mockito.mock;
import static org.mockito.MockitoAnnotations.initMocks;
+import static org.onap.vid.utils.KotlinUtilsKt.JOSHWORKS_JACKSON_OBJECT_MAPPER;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xebialabs.restito.semantics.Action;
import io.joshworks.restclient.http.HttpResponse;
-import io.joshworks.restclient.http.mapper.ObjectMapper;
import java.io.IOException;
import org.assertj.core.api.Assertions;
import org.glassfish.grizzly.http.util.HttpStatus;
@NotNull
private AaiOverTLSClient createAaiOverTLSClient() {
return new AaiOverTLSClient(
- new SyncRestClient(getFasterXmlObjectMapper(), mock(Logging.class)),
+ new SyncRestClient(JOSHWORKS_JACKSON_OBJECT_MAPPER, mock(Logging.class)),
propertySupplier,
serverUtil.constructTargetUrl("http", "")
);
@Test
public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
- ObjectMapper objectMapper = getFasterXmlObjectMapper();
AaiOverTLSClient aaiOverTLSClient = createAaiOverTLSClient();
serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);
}
- private ObjectMapper getFasterXmlObjectMapper() {
- return new ObjectMapper() {
-
- com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
-
- @Override
- public <T> T readValue(String s, Class<T> aClass) {
- try {
- return om.readValue(s, aClass);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public String writeValue(Object o) {
- try {
- return om.writeValueAsString(o);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- };
- }
-
}
import static org.mockito.Mockito.when;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
+import static org.onap.vid.utils.KotlinUtilsKt.JOSHWORKS_JACKSON_OBJECT_MAPPER;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.server.StubServer;
import io.joshworks.restclient.http.HttpResponse;
import java.io.IOException;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controller.MsoController;
-import org.onap.vid.controller.WebConfig;
import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
}
private MsoRestClientNew msoRestClient() {
- final WebConfig webConfig = new WebConfig();
- return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper()), mock(Logging.class)),
+ return new MsoRestClientNew(new SyncRestClient(JOSHWORKS_JACKSON_OBJECT_MAPPER, mock(Logging.class)),
baseUrl(), null, new SystemPropertiesWrapper(), mock(Logging.class));
}