[stringtemplate-interest] ST4: serializable for Template for Template Group?
Terence Parr
parrt at cs.usfca.edu
Tue May 3 16:47:27 PDT 2011
Ok,So I will back out that change, right? No serializable interface implementation.
Ter
On Apr 18, 2011, at 7:44 AM, Udo Borkowski wrote:
>> but I don't think marking those classes as
>> Serializable achieves anything.
>
> It is even worse. It makes StringTemplate (ST4) buggy.
>
> I think is was the uncle of Peter Parker (/Spiderman) who said: "With implementing an interface comes great responsibility" ;-)
>
> When marking these classes as Serializable one must follow the contract associated with this interface. As already mentioned by Rafael this is not the case as there are many fields that are not Serializable and not marked transient.
>
> Also all attributes added to a template need to be Serializable, all AttributeRenderers and all ModelAdaptors, too.
>
> All this restricts the use of ST4 or makes it harder to use. So I suggest to undo this change and check what really is required.
>
> For ST4 this simple test case shows ST4 is currently not ready for default serialization:
>
> public class SerializationTest extends BaseTest {
> @Test
> public void testSerialization() throws Exception {
> String templates = "f() ::= \"foo\"\n";
> writeFile(tmpdir, "t.stg", templates);
> STGroup group = new STGroupFile(tmpdir + "/t.stg");
> ST st = group.getInstanceOf("f");
> String expecting = "foo";
> String result = st.render();
> assertEquals(expecting, result);
>
> File serialFile = new File(tmpdir, "t.ser");
> FileOutputStream fos = new FileOutputStream(serialFile);
> ObjectOutputStream out = new ObjectOutputStream(fos);
> out.writeObject(group);
> out.close();
>
> FileInputStream fis = new FileInputStream(serialFile);
> ObjectInputStream in = new ObjectInputStream(fis);
> STGroup loadedGroup = (STGroup) in.readObject();
> ST st2 = loadedGroup.getInstanceOf("f");
> String result2 = st2.render();
> assertEquals(expecting, result2);
> }
> }
>
> This fails with
>
> java.io.NotSerializableException: org.stringtemplate.v4.misc.ObjectModelAdaptor
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
> …
>
>
>
> Udo
>
>
>
> On 18.04.2011, at 00:19, Rafael Chaves wrote:
>
>> Correct me if I am wrong, but I don't think marking those classes as
>> Serializable achieves anything. In order for them to be serializable
>> using the default mechanism, all of their slots must be serializable,
>> or marked as volatile, which is not the case for the error listener in
>> StringTemplate/StringTemplateGroup, for instance, at least in version
>> 3.
>>
>> On Sun, Apr 17, 2011 at 11:56 AM,
>> <stringtemplate-interest-request at antlr.org> wrote:
>>> Date: Sun, 17 Apr 2011 09:37:10 -0700
>>> From: Terence Parr <parrt at cs.usfca.edu>
>>> Subject: Re: [stringtemplate-interest] ST4: serializable for Template
>>> for Template Group?
>>> To: stringtemplate-interest List <stringtemplate-interest at antlr.org>
>>> Message-ID: <A21307C9-2AAD-4740-BD2C-936FE9705F62 at cs.usfca.edu>
>>> Content-Type: text/plain; charset=us-ascii
>>>
>>> Hmm...oh,So you don't want me to actually specify the implementation, just insert "implements Serializable"?
>>>
>>> Ter
>>> On Apr 15, 2011, at 7:07 AM, Collin Fagan wrote:
>>>
>>>> Hi Ter,
>>>>
>>>> I've been using ST with Apache Wicket. Wicket uses serialization for short term storage of state. I'd like to be able to serialize a template and/or template group with my wicket page. Can you implement serializable in ST4? It really is just a marker interface, I'm not asking for a long term commit to any particular serialization strategy. Right now I subclass StringTemplateGroup and StringTemplate in ST3 and impliment Serializable to get around this.
>>>>
>>>> Thanks,
>>>>
>>>> Collin
>>>> _______________________________________________
>>>> stringtemplate-interest mailing list
>>>> stringtemplate-interest at antlr.org
>>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110503/5e672d74/attachment-0001.html
More information about the stringtemplate-interest
mailing list