Reputation: 1542
I am working with serialized data from Wordpress database. Strings created with PHP serialize function and look something like this:
a:4:{s:6:"weight";s:2:"15";s:6:"length";s:1:"8";s:5:"width";s:1:"8";s:6:"height";s:2:"17";}
Is there a way to deserialize this in Groovy? or is this not a product of standardized serialization?
Thanks!
Upvotes: 0
Views: 355
Reputation: 171144
Here's an example using the pherialize
library
@GrabResolver( name='Ailis', root='http://nexus.ailis.de/content/groups/public' )
@Grab( 'de.ailis.pherialize:pherialize:1.2.1' )
import de.ailis.pherialize.*
def phpValue = 'a:4:{s:6:"weight";s:2:"15";s:6:"length";s:1:"8";s:5:"width";s:1:"8";s:6:"height";s:2:"17";}'
def groovyMap = Pherialize.unserialize( phpValue ).toArray().collectEntries { k, v ->
[ k.toType( k.type ), v.toType( v.type ) ]
}
assert groovyMap == [ weight:'15', length:'8', width:'8', height:'17' ]
Though if possible, I'd suggest you share data between the two in a format they both natively speak (json?)
Upvotes: 3