Skip to content

Instantly share code, notes, and snippets.

@akhikhl
Created November 15, 2014 20:12

Revisions

  1. akhikhl created this gist Nov 15, 2014.
    24 changes: 24 additions & 0 deletions serialize.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // The code below produces ClassNotFoundError. How to fix it?

    import groovy.transform.ToString

    @ToString
    class P2ModuleSource implements Serializable {
    private static final long serialVersionUID = 3526473395612776159L
    List uris
    P2ModuleSource(List uris) {
    this.uris = uris
    }
    }

    def x = new P2ModuleSource(['aaa', 'bbb'])

    def outBytes = new ByteArrayOutputStream()
    def outs = new ObjectOutputStream(outBytes)
    outs.writeObject(x)
    outs.close()
    def bytes = outBytes.toByteArray()

    def inBytes = new ByteArrayInputStream(bytes)
    def ins = new ObjectInputStream(inBytes)
    def y = ins.readObject()