Uploaded image for project: 'apiman (API Management)'
  1. apiman (API Management)
  2. APIMAN-151

Policy serialization to JSON

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.0.x, 1.0.0.Beta
    • 1.0.0.Alpha
    • Policy
    • None

      PolicyConfig on Policy is defined as transient, however that is ignored by Jackson (Jackson does not look at the member variables but at the getter/setters instead). So if one serialized a policy to JSON it looks like:

      "policies" : [ {
              "policyJsonConfig" : "{ \"ipList\" : [ \"127.0.0.1\", \"localhost\" ] }",
              "policyImpl" : "class:org.overlord.apiman.engine.policies.IPWhitelistPolicy",
              "policyConfig" : {
                "ipList" : [ "localhost", "127.0.0.1" ]
              }
            } ]
      

      Upon deserializion jackson turns the policyConfig into a LinkedHashMap, which leads to:

      ERROR | Gateway Internal Error: java.util.LinkedHashMap cannot be cast to org.overlord.apiman.engine.policies.config.IPWhitelistConfig
      java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.overlord.apiman.engine.policies.config.IPWhitelistConfig
      	at org.overlord.apiman.engine.policies.IPWhitelistPolicy.doApply(IPWhitelistPolicy.java:32)[apiman-rt-engine-policies-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
      	at org.overlord.apiman.engine.policies.AbstractPolicy.apply(AbstractPolicy.java:64)[apiman-rt-engine-policies-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
      	at org.overlord.apiman.rt.engine.policy.PolicyChainImpl.doApply(PolicyChainImpl.java:65)[file:/Users/kstam/osc/jboss/git/apiman/apiman-rt/apiman-rt-engine/apiman-rt-engine-core/target/classes/:]
      	at org.overlord.apiman.rt.engine.impl.EngineImpl.execute(EngineImpl.java:163)[file:/Users/kstam/osc/jboss/git/apiman/apiman-rt/apiman-rt-engine/apiman-rt-engine-core/target/classes/:]
      

      The following annotation should be added to the policyConfig field:

      @JsonIgnore
      

              ewittman@redhat.com Eric Wittmann
              kstam@redhat.com Kurt Stam (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: