Class Metadata Selector (.^class)

Class Metadata Selector (.^class)

Returns the class of the Plain Old Java Object (POJO). The value might result from calling a method in a Java class or have a data type (such as String or DateTime) that DataWeave treats as a Java value, for example:

  • { “string” : payload.mystring.^class } might return { “mystring”: “java.lang.String” } if the input payload defines a Java string, such as simplePojo.string = “myString”, in a simple POJO.
  • { “mydate” : payload.mydate.^class } might return { “mydate”: “java.util.Date” }.

In the following Mule app flow, the Logger uses payload.^class to select the Java class of “my string”, set in the Set Payload (set-payload) component.

Mule App XML in Anypoint Studio:

<flow name=”setpayloadobjectFlow” >

<scheduler doc:name=”Scheduler” >

<scheduling-strategy >

<fixed-frequency frequency=”15″ timeUnit=”SECONDS”/>

</scheduling-strategy>

</scheduler>

<!– Set the payload to “my string”. –>

<set-payload value='”my string”‘ doc:name=”Set Payload” />

<!– Select the class to which “my string” belongs. –>

<logger level=”INFO” doc:name=”Logger” message=”#[payload.^class]”/>

</flow>

The Studio console output shows that the payload string belongs to the class java.lang.String.

Console Output in Anypoint Studio:

INFO  2019-04-20 16:10:03,075 [[MuleRuntime].cpuLight.08:

[setpayloadobject].setpayloadobjectFlow.CPU_LITE @6447187e]

[event: 6da29400-63c1-11e9-98e0-8c8590a99d48]

org.mule.runtime.core.internal.processor.LoggerMessageProcessor:

java.lang.String

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

Instagram

Facebook

Recent Posts

What is object oriented design patterns

A design pattern is a reusable solution to a commonly occurring problem in software design. They…

1 month ago

Factory Method Design Pattern in OODP

Factory Method is a creational design pattern that deals with the object creation. It separates…

1 month ago

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

7 months ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

7 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

8 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

8 months ago