Skip to content

JsonTransform transforms template #263

@nilvon9wo

Description

@nilvon9wo

We are using JUST templates to transform messages coming out of Salesforce to abstractions which better suit our business needs and mask the Salesforce implementation details. There is a lot of abstraction within this process so we don't need to hardcode either the input or output models nor even the transformations as we can store JUST templates in a Mongo database.

When dealing with Salesforce, one must bulkify everything (which is probably a good rule of thumb for most development), which exposes a bug in how JUST.Transform(JObject transformer, JToken input) seems to be working.

I can execute this method:

	public Message CreateOutboundMessage(SubscriptionMessage message, ServiceBusDispatchSalesforceSubscriptionSettings settings)
	{
		JObject jsonPayload = JObject.FromObject(message);
		JToken transformedPayload = settings.JustTemplate != null
			? _jsonTransformer.Transform(settings.JustTemplate, jsonPayload)
			: jsonPayload;
		Message outboundMessage = new()
		{
			BusDomain = settings.AzureDomain,
			EntityPath = settings.AzureTopic,
			Body = Encoding.UTF8.GetBytes(transformedPayload.ToString(Formatting.None)),
			ContentType = "application/json"
		};
		return AddCustomProperties(outboundMessage, jsonPayload, settings);
	}

and the output is correct.

However, when multiple messages are processed, only the first message is correct and the rest are identical to the first.
Inspecting with the debugger reveals that when _jsonTransformer.Transform(settings.JustTemplate, jsonPayload) is executed, the value of settings.JustTemplate is modified such that all subsequent invocations will receive the same value.

We should be able to fix this in by cloning the value of settings.JustTemplate before consuming a clone of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions