简体   繁体   中英

Deserialize java serialized object to Scala class

I need to read a serialized object (done in Java) from Redis database) and convert it to a case class in Scala.

The serialized object is like this:

sr?models.mongo.Memberxrcom.mongodb.BasicDBObject¹Ʒ# Z?_isPartialObjectxrorg.bson.BasicBSONObject¹Ʒ# xrjava.util.LinkedHashMap4 N\\?l Z?accessOrderxrjava.util.HashMap ` F loadFactorI thresholdxp?@w ?t_idsrorg.bson.types.ObjectId¹Ʒ# I_incI_machineZ_newI_timexp6 Uҕ t addressessrcom.mongodb.BasicDBList¹Ʒ# Z?_isPartialObjectxrorg.bson.types.BasicBSONList¹Ʒ# xr?java.util.ArrayListx a Isizexpwsq~?@w tidsr?java.lang.Long; ̏# Jvaluexr?java.lang.Number ? xp,#t first_nametsdsdt last_nametsdsdt?contact_numberttstreett?Tuas Avenue 13t?building_not13t address_typetStbuildingq~t company_nameq~tfloorq~t?unit_numberq~tcitytSGtcountrytSGtgeolocsq~?@ w?tsourcetonemapttypetPointt?coordinatessq~ mobile_numberptpostcodet638985ttypesrjava.lang.Integer⠤ 8Ivaluexq~tprioritysq~9tsourcetSINGPOSTt source_idsq~? xxtchanneltIGG, firefox(40) on mac os x (desktop), 6bfda0b, 2015-08-17 12:0 8:35 +0800temailtbaskaran+0022@redmart.comt first_nameq~tidsq~? t in_groupssq~ wsq~?@ w?tidq~ wxtpasswordt#b68f58941b89d64d33f522c7d83d7031:3utpostcodet638985t?referral_tokentbaskaran0022118508tstatussq~9?tintercomt@e610edfc94b3086dffc8e3fd8709e6e29c2bf9213ec7b83ffd77df40918cc349x

Any idea?

You need to deserialize it in the normal Java way, getting a Java object (namely a models.mongo.Member ). Note that for this you'll need the jar file which contains the models.mongo.Member class, preferably the exact same version which was used to serialize the object (otherwise it may not work correctly). Then convert it to a case class in whatever way you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM