Skip to content

Commit

Permalink
Merge pull request #49 from ath0s/JACKSON2
Browse files Browse the repository at this point in the history
#48 Upgrade from Jackson 1.9.12 to Jackson 2.8.6.
  • Loading branch information
joakimsahlstrom authored Jan 31, 2017
2 parents 7e0bb2a + 55f526b commit 39e29be
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.util.Arrays;
import java.util.List;

import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.Jackson1ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson1.JacksonObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.Jackson2ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson2.JacksonObjectMapperBuilder;

public class ServiceRegistryObjectSerializerConfigurer implements Jackson1ObjectSerializerConfigurer {
public class ServiceRegistryObjectSerializerConfigurer implements Jackson2ObjectSerializerConfigurer {

public static final int VERSION = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/
package com.avanza.astrix.beans.registry;

import org.codehaus.jackson.node.ObjectNode;

import com.avanza.astrix.beans.service.ServiceProperties;
import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.AstrixJsonMessageMigration;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.AstrixJsonMessageMigration;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class ServiceRegistryV1ApiMigration implements AstrixJsonApiMigration {

Expand All @@ -46,8 +45,8 @@ public void upgrade(ObjectNode json) {
// ApplicationInstanceId concept was introduced to uniquely identify a service.
// Old clients will not set the property, but it was expected that a service (api + qualifier)
// was only provided by a single application instance, hence we use it as id.
String qualifier = json.get("serviceProperties").get("_qualifier").getTextValue();
String api = json.get("serviceProperties").get("_api").getTextValue();
String qualifier = json.get("serviceProperties").get("_qualifier").asText();
String api = json.get("serviceProperties").get("_api").asText();
String applicationInstanceId = api + "_" + qualifier;
ObjectNode.class.cast(json.get("serviceProperties")).put(ServiceProperties.APPLICATION_INSTANCE_ID, applicationInstanceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,9 @@
package com.avanza.astrix.context;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.*;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.avanza.astrix.beans.api.ApiProviderBeanPublisherModule;
import com.avanza.astrix.beans.config.AstrixConfig;
import com.avanza.astrix.beans.config.AstrixConfigModule;
Expand All @@ -46,48 +33,31 @@
import com.avanza.astrix.beans.core.AstrixSettings;
import com.avanza.astrix.beans.factory.BeanFactoryModule;
import com.avanza.astrix.beans.factory.StandardFactoryBean;
import com.avanza.astrix.beans.ft.BeanFaultToleranceFactorySpi;
import com.avanza.astrix.beans.ft.DefaultHystrixCommandNamingStrategy;
import com.avanza.astrix.beans.ft.FaultToleranceModule;
import com.avanza.astrix.beans.ft.HystrixCommandNamingStrategy;
import com.avanza.astrix.beans.ft.NoFaultTolerance;
import com.avanza.astrix.beans.publish.ApiProviderClass;
import com.avanza.astrix.beans.publish.ApiProviderPlugins;
import com.avanza.astrix.beans.publish.ApiProviders;
import com.avanza.astrix.beans.publish.BeanPublisherPlugin;
import com.avanza.astrix.beans.publish.BeansPublishModule;
import com.avanza.astrix.beans.ft.*;
import com.avanza.astrix.beans.publish.*;
import com.avanza.astrix.beans.registry.AstrixServiceRegistryLibraryProvider;
import com.avanza.astrix.beans.registry.AstrixServiceRegistryServiceProvider;
import com.avanza.astrix.beans.registry.ServiceRegistryDiscoveryModule;
import com.avanza.astrix.beans.service.DirectComponentModule;
import com.avanza.astrix.beans.service.ServiceModule;
import com.avanza.astrix.config.DynamicConfig;
import com.avanza.astrix.config.LongSetting;
import com.avanza.astrix.config.MapConfigSource;
import com.avanza.astrix.config.PropertiesConfigSource;
import com.avanza.astrix.config.Setting;
import com.avanza.astrix.config.SystemPropertiesConfigSource;
import com.avanza.astrix.config.*;
import com.avanza.astrix.context.mbeans.AstrixMBeanModule;
import com.avanza.astrix.context.mbeans.MBeanServerFacade;
import com.avanza.astrix.context.mbeans.PlatformMBeanServer;
import com.avanza.astrix.context.metrics.DefaultMetricSpi;
import com.avanza.astrix.context.metrics.MetricsModule;
import com.avanza.astrix.context.metrics.MetricsSpi;
import com.avanza.astrix.modules.Module;
import com.avanza.astrix.modules.ModuleContext;
import com.avanza.astrix.modules.ModuleInstancePostProcessor;
import com.avanza.astrix.modules.Modules;
import com.avanza.astrix.modules.ModulesConfigurer;
import com.avanza.astrix.modules.StrategyContextPreparer;
import com.avanza.astrix.modules.StrategyProvider;
import com.avanza.astrix.modules.*;
import com.avanza.astrix.provider.core.AstrixApiProvider;
import com.avanza.astrix.provider.core.AstrixExcludedByProfile;
import com.avanza.astrix.provider.core.AstrixIncludedByProfile;
import com.avanza.astrix.serviceunit.AstrixApplicationDescriptor;
import com.avanza.astrix.serviceunit.ServiceUnitModule;
import com.avanza.astrix.serviceunit.SystemServiceApiProvider;
import com.avanza.astrix.versioning.core.ObjectSerializerModule;
import com.avanza.astrix.versioning.jackson1.Jackson1SerializerModule;
import com.avanza.astrix.versioning.jackson2.Jackson2SerializerModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Used to configure and create an {@link AstrixContext}. <p>
*
Expand Down Expand Up @@ -151,7 +121,7 @@ public AstrixContext configure() {
modulesConfigurer.register(new BeansPublishModule());
modulesConfigurer.register(new ServiceModule());
modulesConfigurer.register(new ObjectSerializerModule());
modulesConfigurer.register(new Jackson1SerializerModule());
modulesConfigurer.register(new Jackson2SerializerModule());
modulesConfigurer.register(new ApiProviderBeanPublisherModule());
modulesConfigurer.register(new FaultToleranceModule());
modulesConfigurer.register(new BeanFactoryModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.util.Collections;
import java.util.List;

import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.Jackson1ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson1.JacksonObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.Jackson2ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson2.JacksonObjectMapperBuilder;

public class ServiceAdministratorVersioningConfigurer implements Jackson1ObjectSerializerConfigurer {
public class ServiceAdministratorVersioningConfigurer implements Jackson2ObjectSerializerConfigurer {

@Override
public List<? extends AstrixJsonApiMigration> apiMigrations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
import java.util.Arrays;
import java.util.List;

import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.Jackson1ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson1.JacksonObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.Jackson2ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson2.JacksonObjectMapperBuilder;


public class LunchApiObjectSerializerConfigurer implements Jackson1ObjectSerializerConfigurer {
public class LunchApiObjectSerializerConfigurer implements Jackson2ObjectSerializerConfigurer {

@Override
public List<? extends AstrixJsonApiMigration> apiMigrations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/
package com.avanza.astrix.integration.tests.domain.apiruntime;

import org.codehaus.jackson.node.ObjectNode;

import com.avanza.astrix.integration.tests.domain.api.LunchRestaurant;
import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.AstrixJsonMessageMigration;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.AstrixJsonMessageMigration;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class LunchApiV1Migration implements AstrixJsonApiMigration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import java.util.Collections;
import java.util.List;

import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.Jackson1ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson1.JacksonObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.Jackson2ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson2.JacksonObjectMapperBuilder;

public class LunchGradeApiObjectMapperConfigurer implements Jackson1ObjectSerializerConfigurer {
public class LunchGradeApiObjectMapperConfigurer implements Jackson2ObjectSerializerConfigurer {

@Override
public void configure(JacksonObjectMapperBuilder objectMapperBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
*/
package com.avanza.astrix.integration.tests;

import static com.avanza.astrix.beans.core.AstrixSettings.APPLICATION_INSTANCE_ID;
import static com.avanza.astrix.beans.core.AstrixSettings.APPLICATION_TAG;
import static com.avanza.astrix.beans.core.AstrixSettings.BEAN_BIND_ATTEMPT_INTERVAL;
import static com.avanza.astrix.beans.core.AstrixSettings.SERVICE_ADMINISTRATOR_COMPONENT;
import static com.avanza.astrix.beans.core.AstrixSettings.SERVICE_LEASE_RENEW_INTERVAL;
import static com.avanza.astrix.beans.core.AstrixSettings.SERVICE_REGISTRY_URI;
import static com.avanza.astrix.beans.core.AstrixSettings.SUBSYSTEM_NAME;
import static com.avanza.astrix.beans.core.AstrixSettings.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand All @@ -32,16 +26,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;

import com.avanza.astrix.beans.core.AstrixBeanKey;
import com.avanza.astrix.beans.core.AstrixSettings;
import com.avanza.astrix.beans.registry.AstrixServiceRegistryEntry;
Expand All @@ -67,9 +51,18 @@
import com.avanza.astrix.versioning.core.AstrixObjectSerializerConfig;
import com.avanza.astrix.versioning.core.AstrixObjectSerializerConfigurer;
import com.avanza.astrix.versioning.core.Versioned;
import com.avanza.astrix.versioning.jackson1.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson1.Jackson1ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson1.JacksonObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.AstrixJsonApiMigration;
import com.avanza.astrix.versioning.jackson2.Jackson2ObjectSerializerConfigurer;
import com.avanza.astrix.versioning.jackson2.JacksonObjectMapperBuilder;
import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
/**
*
* @author Elias Lindholm (elilin)
Expand Down Expand Up @@ -403,7 +396,7 @@ public static interface AccountPerformaneApi {
AccountPerformanceInternal accountPerformanceInternal();
}

public static class AccountPerformanceVersioningConfig implements Jackson1ObjectSerializerConfigurer {
public static class AccountPerformanceVersioningConfig implements Jackson2ObjectSerializerConfigurer {
@Override
public List<? extends AstrixJsonApiMigration> apiMigrations() {
return Collections.emptyList();
Expand Down
9 changes: 4 additions & 5 deletions astrix-versioning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
<artifactId>astrix-modules</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;

import org.codehaus.jackson.node.ObjectNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;


public interface AstrixObjectMapperConfigurer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;

import java.lang.reflect.Type;

import com.avanza.astrix.versioning.core.AstrixObjectSerializer;
import com.avanza.astrix.versioning.core.AstrixObjectSerializerConfigurer;
import com.avanza.astrix.versioning.core.ObjectSerializerDefinition;
import com.avanza.astrix.versioning.jackson1.VersionedJsonObjectMapper.VersionedObjectMapperBuilder;
import com.avanza.astrix.versioning.jackson2.VersionedJsonObjectMapper.VersionedObjectMapperBuilder;

class Jackson1AstrixObjectSerializer implements AstrixObjectSerializer {
class Jackson2AstrixObjectSerializer implements AstrixObjectSerializer {

private JsonObjectMapper objectMapper;
private int version;

public Jackson1AstrixObjectSerializer(ObjectSerializerDefinition serializerDefinition) {
public Jackson2AstrixObjectSerializer(ObjectSerializerDefinition serializerDefinition) {
Class<? extends AstrixObjectSerializerConfigurer> serializerBuilder = serializerDefinition.getObjectSerializerConfigurerClass();
this.version = serializerDefinition.version();
try {
this.objectMapper = buildObjectMapper(Jackson1ObjectSerializerConfigurer.class.cast(serializerBuilder.newInstance()));
this.objectMapper = buildObjectMapper(Jackson2ObjectSerializerConfigurer.class.cast(serializerBuilder.newInstance()));
} catch (Exception e) {
throw new RuntimeException("Failed to init JsonObjectMapper", e);
}
}

private JsonObjectMapper buildObjectMapper(Jackson1ObjectSerializerConfigurer serializerBuilder) {
private JsonObjectMapper buildObjectMapper(Jackson2ObjectSerializerConfigurer serializerBuilder) {
VersionedObjectMapperBuilder objectMapperBuilder = new VersionedObjectMapperBuilder(serializerBuilder.apiMigrations());
serializerBuilder.configure(objectMapperBuilder);
return JsonObjectMapper.create(objectMapperBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;

import java.util.List;

Expand All @@ -23,7 +23,7 @@
* @author Elias Lindholm
*
*/
public interface Jackson1ObjectSerializerConfigurer extends AstrixObjectSerializerConfigurer {
public interface Jackson2ObjectSerializerConfigurer extends AstrixObjectSerializerConfigurer {
List<? extends AstrixJsonApiMigration> apiMigrations();
void configure(JacksonObjectMapperBuilder objectMapperBuilder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.avanza.astrix.versioning.jackson1;
package com.avanza.astrix.versioning.jackson2;

import com.avanza.astrix.modules.Module;
import com.avanza.astrix.modules.ModuleContext;
import com.avanza.astrix.versioning.core.ObjectSerializerFactoryPlugin;

public class Jackson1SerializerModule implements Module {
public class Jackson2SerializerModule implements Module {

@Override
public void prepare(ModuleContext moduleContext) {
moduleContext.bind(ObjectSerializerFactoryPlugin.class, Jackson1SerializerPlugin.class);
moduleContext.bind(ObjectSerializerFactoryPlugin.class, Jackson2SerializerPlugin.class);

moduleContext.export(ObjectSerializerFactoryPlugin.class);
}
Expand Down
Loading

0 comments on commit 39e29be

Please sign in to comment.