Use of protobuf messages as SoyRecords now deprecated?

90 views
Skip to first unread message

o...@fleaflicker.com

unread,
Apr 9, 2018, 11:59:03 AM4/9/18
to Closure Templates Discuss
After ac4b1db Closure Templates issues a warning about using protobuf messages as the input SoyRecord to a template.

We have many templates that defined their input params using soy types but passed SoyRecords to them using a protobuf message because it's easier to set its values.

I'm confused about how to modify our templates for future compatibility. 

It looks like this following approach is now deprecated:

{template .test}
  {@param number: int}
  {@param aFlag: bool}
  {@param textList: list<string>}
{/template}

Then define a protobuf message to build up the input params for SoyTofu:

message TestSoyRecord {
  int32 number = 1;
  bool a_flag = 2;
  repeated text = 3;
}

This way the template's inputs are explicitly listed but it's also easy to assemble the input SoyRecord with a strongly-typed interface:

tofu.newRenderer(...).setData(SoyProtoValueImpl.create(
  TestSoyRecord.newBuilder().setNumber(4).addText("xyz").setAFlag(true).build()
))

Is this approach now deprecated? 

Eric Spishak-Thomas

unread,
Apr 11, 2018, 10:05:46 AM4/11/18
to closure-temp...@googlegroups.com, o...@fleaflicker.com
Hi Ori,

We never actually intended for protos to be passed as data that way. It's a clever way to get more type checking, but unfortunately unsupported. SoyProtoValue implementing SoyRecord was a bad decision we made a while ago for compatibility reasons and we're slowly trying to back our way out of it. The correct way going forward is to pass data in as a Map<String, ?> (using https://github.com/google/closure-templates/blob/0339f57eda8624125f17539874e337552287ed7a/java/src/com/google/template/soy/tofu/SoyTofu.java#L126). We realize there's no type checking on this and we've tossed around the idea of having a strongly typed builder-type interface for setting data, but have no ETA.

Thanks,

Eric

--

---
You received this message because you are subscribed to the Google Groups "Closure Templates Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-templates-discuss+unsubsc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages