0

I have this LinkedHashMap and LinkedHashMap$Entry payload

{box=
   {
     0={plate=false, id=8269999, knife=1}, 
     1={plate=true, id=8260118, knife=1}
   }
}

I want to apply this structure to my Dataweave transformation sample data. I came up with this but the transformation fails during runtime, while preview shows it is a correct transformation...

%dw 1.0
%output application/java
---
[{
  "box": {
    "0": {
      "plate": {
        plate: false
      } as :object {
        class : "java.util.Object"
      },
      "id": {
        id: 8269999
      } as :object {
        class : "java.util.Object"
      },
      "knife": {
        knife: 1
      } as :object {
        class : "java.util.Object"
      }
    } as :object {
      class : "java.util.Object"
    },
    "1": {
      "plate": {
        plate: true
      } as :object {
        class : "java.util.Object"
      },
      "id": {
        id: 8260118
      } as :object {
        class : "java.util.Object"
      },
      "knife": {
        knife: 1
      } as :object {
        class : "java.util.Object"
      }
    } as :object {
      class : "java.util.Object"
    }
  } as :object {
    class : "java.util.Object"
  }
} as :object {
  class : "java.util.LinkedHashMap"
}]
Tomeister
  • 675
  • 2
  • 9
  • 26
  • 1
    You can remove all the `as :object {class : "java.util.Object"}` also can you paste the execption, add runtime information (version of mule you are using). – machaval Mar 08 '19 at 20:26

1 Answers1

0

java.util.Object doesn't have fields like knife or plate so it would not make any sense to cast to it. What you want is to just remove all the 'as :object...' in your script and DataWeave will return maps as needed.

Also usually the entries in a map (ie LinkedHashMap$Entry) are not referenced directly at all. They are an implementation detail of the specific map implementation.

Just think in terms of the Map interface, not a specific implementation like LinkedHashMap.

aled
  • 21,330
  • 3
  • 27
  • 34