Search code examples
freemarker

Freemarker decompose final .txt back to model based on .ftl


I have been using FreeMarker long time now ... currently we had the below problem :

Let's say we have an .ftl file like below :

Bank File
Data : ${content.data}
Company Name : ${content.companyName}

We finally have a .txt file like :

Bank File
Data : someData
Company Name : stackoverflow.com

Let's say we have this model for FreeMarker :

public class Model {

 private String data;
 private String companyName;

 ...getters and setters below

}

Now is there any way to do the opposite ? From the final .txt file to get back the data to the model ?

I not let me know what is the best approach for this :) ? The receiver is replying with a message exactly the same but with different data .


Solution

  • There's no such facility in FreeMarker. Furthermore it's in general impossible to do; consider conditional blocks and loops, macro calls... Of course for very restricted templates, one can work out a such solution. But I think a realistic solution would involve some markers in the output, like some tags around the fields that aren't visible in rendering. But for plain text you can't even have tags of course...