diff --git a/eureka-client/src/main/java/com/netflix/discovery/converters/EurekaJacksonCodec.java b/eureka-client/src/main/java/com/netflix/discovery/converters/EurekaJacksonCodec.java index 0c9d8e585..f14da0e38 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/converters/EurekaJacksonCodec.java +++ b/eureka-client/src/main/java/com/netflix/discovery/converters/EurekaJacksonCodec.java @@ -105,6 +105,22 @@ public class EurekaJacksonCodec { public static EurekaJacksonCodec INSTANCE = new EurekaJacksonCodec(); + public static final Supplier> METADATA_MAP_SUPPLIER; + + static { + boolean useCompact = true; + try { + Class.forName("vlsi.utils.CompactHashMap"); + } catch (ClassNotFoundException e) { + useCompact = false; + } + if (useCompact) { + METADATA_MAP_SUPPLIER = CompactHashMap::new; + } else { + METADATA_MAP_SUPPLIER = HashMap::new; + } + } + /** * XStream codec supports character replacement in field names to generate XML friendly * names. This feature is also configurable, and replacement strings can be provided by a user. @@ -622,7 +638,7 @@ public InstanceInfo deserialize(JsonParser jp, DeserializationContext context) t String key = intern.apply(jp, CacheScope.GLOBAL_SCOPE); jsonToken = jp.nextToken(); String value = intern.apply(jp, CacheScope.APPLICATION_SCOPE ); - metadataMap = Optional.ofNullable(metadataMap).orElseGet(CompactHashMap::new); + metadataMap = Optional.ofNullable(metadataMap).orElseGet(METADATA_MAP_SUPPLIER); metadataMap.put(key, value); } }; diff --git a/eureka-client/src/main/java/com/netflix/discovery/converters/jackson/builder/StringInterningAmazonInfoBuilder.java b/eureka-client/src/main/java/com/netflix/discovery/converters/jackson/builder/StringInterningAmazonInfoBuilder.java index 6a9b79a16..e53302ba6 100644 --- a/eureka-client/src/main/java/com/netflix/discovery/converters/jackson/builder/StringInterningAmazonInfoBuilder.java +++ b/eureka-client/src/main/java/com/netflix/discovery/converters/jackson/builder/StringInterningAmazonInfoBuilder.java @@ -28,12 +28,11 @@ import com.netflix.appinfo.AmazonInfo.MetaDataKey; import com.netflix.appinfo.DataCenterInfo.Name; import com.netflix.discovery.converters.EnumLookup; +import com.netflix.discovery.converters.EurekaJacksonCodec; import com.netflix.discovery.util.DeserializerStringCache; import com.netflix.discovery.util.DeserializerStringCache.CacheScope; import com.netflix.discovery.util.StringCache; -import vlsi.utils.CompactHashMap; - /** * Amazon instance info builder that is doing key names interning, together with * value interning for selected keys (see {@link StringInterningAmazonInfoBuilder#VALUE_INTERN_KEYS}). @@ -109,7 +108,7 @@ private void skipToEnd(JsonParser jp) throws IOException { @Override public AmazonInfo deserialize(JsonParser jp, DeserializationContext context) throws IOException { - Map metadata = new CompactHashMap<>(); + Map metadata = EurekaJacksonCodec.METADATA_MAP_SUPPLIER.get(); DeserializerStringCache intern = DeserializerStringCache.from(context); if (skipToMetadata(jp)) {