Nel
Nel

Reputation: 179

Can't construct a java object due to "Invalid tag" error

I built a web application that communicates with a Redis cache cluster via Redisson driver. The Redisson driver loads its configuration from a YAML file. The configuration contains a couple of attributes that are created using a constructor for object creation. For some reason the configuration fails to load due to these constructor method calls with the following error:

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SessionManagement]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:939)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1812)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: Can't construct a java object for org.redisson.connection.balancer.RoundRobinLoadBalancer; exception=Invalid tag: org.redisson.connection.balancer.RoundRobinLoadBalancer
 in 'reader', line 14, column 17:
      loadBalancer: !<org.redisson.connection.balanc ... 
                    ^

    at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:350)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:373)

Here is the YAML file:

---
clusterServersConfig:
  idleConnectionTimeout: 10000
  pingTimeout: 1000
  connectTimeout: 1000
  timeout: 1000
  retryAttempts: 3
  retryInterval: 1000
  reconnectionTimeout: 3000
  failedAttempts: 3
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
  slaveSubscriptionConnectionMinimumIdleSize: 1
  slaveSubscriptionConnectionPoolSize: 25
  slaveConnectionMinimumIdleSize: 5
  slaveConnectionPoolSize: 100
  masterConnectionMinimumIdleSize: 5
  masterConnectionPoolSize: 100
  readMode: "SLAVE"
  nodeAddresses:
  - "//172.31.150.113:7000"
  - "//172.31.150.113:7001"
  - "//172.31.150.113:7002"
  - "//172.31.150.113:7003"
  - "//172.31.150.113:7004"
  - "//172.31.150.113:7005"
  scanInterval: 1000
threads: 0
codec: !<org.redisson.codec.JsonJacksonCodec> {}
useLinuxNativeEpoll: false
eventLoopGroup: null

I verified that the required redisson libraries for the object creations are on the classpath.
Does anyone have an idea why this YAML file fails to be loaded correctly by Snakeyaml?

Upvotes: 1

Views: 3059

Answers (1)

kaliatech
kaliatech

Reputation: 17867

When using that form to load as javabean with no predefined tag, I believe the syntax is two exclamation points and no surrounding markers. i.e.

codec: !!org.redisson.codec.JsonJacksonCodec{}

If loading as class with constructor and a predefined tag, then brackets instead of braces:

codec: !org.redisson.codec.JsonJacksonCodec[]

If that doesn't help, consider also posting which version of Snakeyaml you are using.

Upvotes: 2

Related Questions