DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache

Trending

  • Why SQL Server Applications Break on PostgreSQL and How Compatibility Layers Fix It
  • Lift-and-Shift vs. Modernize: A Decision Framework for Enterprise Workloads
  • The Invisible OOMKill: Why Your Java Pod Keeps Restarting in Kubernetes
  • Going Stateless: Scaling MCP Servers to Cloud-Native Java and HTTP

Reading Dynamic Values from a Property File in Dataweave 2.0 (Mule 4)

This short article contains the Dataweave 2.0 code for reading a dynamic value from a property file based on the input passed.

By 
Abhishek Bathwal user avatar
Abhishek Bathwal
·
Jun. 10, 21 · Code Snippet
Likes (1)
Comment
Save
Tweet
Share
14.7K Views

Join the DZone community and get the full member experience.

Join For Free

This short article contains the Dataweave 2.0 code for reading a dynamic value from a property file based on the input passed.

Created a property file that contains the Abbreviation and Description for some defined values.

The property file needs to be configured in Global Elements:

The property file needs to be configured in Global Elements:

Dataweave 2.0 Code

Java
 




x
15


 
1
%dw 2.0
2
import * from dw::core::Strings
3
output application/json
4

          
5
fun lookupvalues(value, property) = 
6
if (value != null and upper(property) == 'ABBRV')
7
substringBefore(p(value replace " " with "-"), '|')
8
else if (value != null and upper(property) == 'DESC')
9
substringAfter(p(value replace " " with "-"), '|')
10
else ''
11
---
12
{
13
    Value: lookupvalues(payload,'abbrv'),
14
    Description: lookupvalues(payload,'desc')
15
}


Testing

Java
 




xxxxxxxxxx
1
11
9


 
1
Input:
2
"RuntimeManager"
3

          
4
Output:
5
{
6
  "Value": "RM",
7
  "Description": "Runtime Manager"
8
}


AnypointStudio values

Mulesoft Values

Property (programming)

Published at DZone with permission of Abhishek Bathwal. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook