[
https://issues.apache.org/jira/browse/CURATOR-67?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13816433#comment-13816433
]
Dan Diodati commented on CURATOR-67:
------------------------------------
Adding the patch to fix the issue can someone check in this fix ?
diff --git
a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceDiscoveryBuilder.java
b/curator-x-discovery/src/main/java/org/apache/curator/x/d
index ab62004..d464a55 100644
---
a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceDiscoveryBuilder.java
+++
b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceDiscoveryBuilder.java
@@ -29,6 +29,7 @@ public class ServiceDiscoveryBuilder<T>
private String basePath;
private InstanceSerializer<T> serializer;
private ServiceInstance<T> thisInstance;
+ private Class<T> payloadClass;
/**
* Return a new builder. The builder will be defaulted with a {@link
JsonInstanceSerializer}.
@@ -39,7 +40,7 @@ public class ServiceDiscoveryBuilder<T>
*/
public static<T> ServiceDiscoveryBuilder<T> builder(Class<T>
payloadClass)
{
- return new ServiceDiscoveryBuilder<T>(payloadClass).serializer(new
JsonInstanceSerializer<T>(payloadClass));
+ return new ServiceDiscoveryBuilder<T>(payloadClass);
}
/**
@@ -49,6 +50,11 @@ public class ServiceDiscoveryBuilder<T>
*/
public ServiceDiscovery<T> build()
{
+
+ if (serializer == null) {
+ serializer = new JsonInstanceSerializer<T>(payloadClass);
+ }
+
return new ServiceDiscoveryImpl<T>(client, basePath, serializer,
thisInstance);
}
@@ -102,5 +108,6 @@ public class ServiceDiscoveryBuilder<T>
ServiceDiscoveryBuilder(Class<T> payloadClass)
{
+ this.payloadClass = payloadClass;
}
}
> Issue with default JSONInstanceSerializer for discovery service builder
> -----------------------------------------------------------------------
>
> Key: CURATOR-67
> URL: https://issues.apache.org/jira/browse/CURATOR-67
> Project: Apache Curator
> Issue Type: New Feature
> Components: Framework
> Affects Versions: 2.2.0-incubating
> Reporter: Dan Diodati
>
> There is a problem with the ServiceDiscoveryBuilder.java not letting me
> provide a custom InstanceSerializer.
> This build creates a new instance of the JsonInstanceSerailzer in the main
> builder method before I get a chance to provide my own instance in the
> serializer method.
> In my case it ends up giving me a incompatible class error due to the fact
> that I have a legacy system which is using an older version of Jackson
> library( ~1.5) which is not binary compatible with the jackson version used
> by ServiceDiscovery (~1.9).
> So I tried to provide my own serializer but the default instance is always
> being created.
> Look at
> https://git-wip-us.apache.org/repos/asf?p=incubator-curator.git;a=blob;f=curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceDiscoveryBuilder.java;h=ab62004e72d138e1195e01ce4d3e2f1a7d4825a6;hb=HEAD
> /**
> 34 * Return a new builder. The builder will be defaulted with a {@link
> JsonInstanceSerializer}.
> 35 *
> 36 * @param payloadClass the class of the payload of your service
> instance (you can use {@link Void}
> 37 * if your instances don't need a payload)
> 38 * @return new builder
> 39 */
> 40 public static<T> ServiceDiscoveryBuilder<T> builder(Class<T>
> payloadClass)
> 41 {
> 42 return new
> ServiceDiscoveryBuilder<T>(payloadClass).serializer(new
> JsonInstanceSerializer<T>(payloadClass));
> 43 }
> So to fix this can we change this to :
> /**
> 34 * Return a new builder. The builder will be defaulted with a {@link
> JsonInstanceSerializer}.
> 35 *
> 36 * @param payloadClass the class of the payload of your service
> instance (you can use {@link Void}
> 37 * if your instances don't need a payload)
> 38 * @return new builder
> 39 */
> 40 public static<T> ServiceDiscoveryBuilder<T> builder(Class<T>
> payloadClass)
> 41 {
> 42 return new ServiceDiscoveryBuilder<T>(payloadClass);
> 43 }
> Then in the build method from:
> 45 /**
> 46 * Build a new service discovery with the currently set values
> 47 *
> 48 * @return new service discovery
> 49 */
> 50 public ServiceDiscovery<T> build()
> 51 {
> 52 return new ServiceDiscoveryImpl<T>(client, basePath, serializer,
> thisInstance);
> 53 }
> To something like:
> 44
> 45 /**
> 46 * Build a new service discovery with the currently set values
> 47 *
> 48 * @return new service discovery
> 49 */
> 50 public ServiceDiscovery<T> build()
> 51 {
> If (serializer == null) {
> serializer = new JsonInstanceSerializer<T>(payloadClass);
> // NOTE Need to add payloadClass as a private data member too
> }
> 52 return new ServiceDiscoveryImpl<T>(client, basePath, serializer,
> thisInstance);
> 53 }
--
This message was sent by Atlassian JIRA
(v6.1#6144)