Meta tags:
description= A presentation of the Serialization Proxy Pattern as defined in Effective Java. It defines the pattern, describes its implementation and gives examples.;
keywords= Serialization Proxy Pattern;
Headings (most frequently used words):
serialization, proxy, the, pattern, implementation, serializing, deserializing,
Text of the page (most frequently used words):
the (65), java (38), serialization (23), proxy (22), #pattern (19), this (16), project (15), original (13), and (11), code (11), instance (10), class (10), its (9), with (9), post (8), for (7), stream (6), fields (5), object (5), there (5), license (5), pros (5), cons (5), junit (5), has (4), byte (4), implementation (4), single (4), examples (4), about (4), your (4), community (4), reflection (4), performance (4), clean (4), will (3), defined (3), following (3), was (3), serializationproxy (3), deserializing (3), new (3), when (3), can (3), serializing (3), only (3), final (3), that (3), possible (3), one (3), check (3), out (3), demo (3), many (3), want (3), follow (3), share (3), blog (3), patterns (3), pioneer (3), demos (3), streams (3), core (3), constructor (2), state (2), create (2), private (2), from (2), method (2), which (2), called (2), after (2), deserialized (2), instead (2), implement (2), well (2), but (2), written (2), often (2), logical (2), representation (2), best (2), lic (2), defines (2), github (2), more (2), know (2), book (2), edition (2), item (2), effective (2), active (2), various (2), platforms (2), watch (2), space (2), get (2), notified (2), publish (2), content (2), problems (2), circular (2), graphs (2), unsuited (2), inheritance (2), conforms (2), responsibility (2), principle (2), higher (2), security (2), flexible (2), instantiation (2), limitation (2), lessened (2), extralinguistic (2), character (2), instancecache (2), complexnumber (2), artificial (2), play (2), around (2), yourself (2), repository (2), contains (2), snippets (2), shown (2), permissive (2), you (2), reuse (2), projects (2), src (2), source (2), talks (2), libfx (2), record (2), args (2), var (2), turn (2), year (2), tools (2), techniques (2), switch (2), records (2), valhalla (2), panama (2), loom (2), leyden (2), amber (2), matching (2), optional (2), ramp (2), migration (2), meta (2), maven (2), libraries (2), lambda (2), javafx (2), next (2), basics (2), j_ms (2), generics (2), dop (2), documentation (2), deprecation (2), libs (2), collections (2), architecture (2), tags (2), works (2), javascript (2), creating, done, via, regular, api, readresolve, deserialization, translation, inverted, implemented, successfully, return, writereplace, serialized, system, informed, write, must, serializable, since, former, never, actually, latter, needs, serial, version, uid, unique, identifier, static, nested, all, are, sole, argument, extracts, assigns, own, considered, safe, need, consistency, checks, defensive, copying, goal, design, such, name, suggests, key, takes, place, graph, applied, mechanism, easier, readability, text, refer, instances, ones, respectively, samples, used, throughout, come, created, details, far, first, joshua, bloch, excellent, 1st, 2nd, mostly, restates, what, said, focuses, presenting, detailed, definition, before, giving, two, short, finally, covering, talked, general, much, focused, presents, detail, good, way, deal, issues, thing, developer, would, topic, tell, them, last, toc, table, contents, artist, dev, presentation, describes, gives, 2014, privacy, slides, upcoming, past, schedule, recordings, virtual, threads, vector, structured, concurrency, lilliput, galahad, babylon, openjdk, conversation, club, videos, jms, newsletter, posts, testing, rant, jigsaw, jdeps, impulse, default, methods, lang, review, comments, words, rss, stackoverflow, twitch, youtube, discord, mastodon, bluesky, site, without, even, better, enabled, nipafx,
Text of the page (random words):
the serialization proxy pattern nipafx this site works well without javascript but it works even better with javascript enabled bluesky mastodon discord youtube twitch github stackoverflow rss words tags architecture clean code clean comments code review collections community core lang core libs default methods deprecation documentation dop generics impulse j_ms java 10 java 11 java 12 java 13 java 16 java 17 java 18 java 20 java 23 java 24 java 25 java 26 java 27 java 8 java 9 java basics java next javafx jdeps js junit 5 junit pioneer lambda libfx libraries maven meta migration on ramp optional pattern matching patterns performance project amber project jigsaw project leyden project loom project panama project valhalla rant record args records reflection serialization streams switch techniques testing tools turn of the year var blog posts newsletter the jms videos tags ai architecture book club clean code collections community conversation core libs deprecation documentation dop generics j_ms java 10 java 11 java 12 java 16 java 17 java 18 java 19 java 21 java 22 java 23 java 24 java 25 java 26 java 27 java 28 java 8 java 9 java basics java next javafx junit 5 junit pioneer lambda libraries maven meta migration on ramp openjdk optional pattern matching patterns performance project amber project babylon project galahad project leyden project lilliput project loom project panama project valhalla records reflection serialization streams structured concurrency switch techniques tools turn of the year var vector virtual threads recordings streams schedule code demos demos demos junit pioneer record args libfx talks my talks past upcoming slides about about me license privacy 2014 10 29 the serialization proxy pattern post clean code patterns serialization a presentation of the serialization proxy pattern as defined in effective java it defines the pattern describes its implementation and gives examples src source dev artist lic license the serialization proxy pattern source code want to play around with the code yourself check out the repository serialization proxy pattern a demo of the serialization proxy pattern it contains many of the snippets shown in this blog post it has a permissive license so you can reuse the code for your projects table of contents serialization proxy pattern the serialization proxy implementation serializing deserializing artificial byte stream examples complexnumber instancecache pros and cons pros lessened extralinguistic character no limitation on final fields flexible instantiation higher security conforms to the single responsibility principle cons unsuited for inheritance possible problems with circular object graphs performance reflection share follow share this post with your community i m active on various platforms watch this space or follow me there to get notified when i publish new content src want to play around with the code yourself check out the repository serialization proxy pattern a demo of the serialization proxy pattern it contains many of the snippets shown in this blog post it has a permissive license so you can reuse the code for your projects toc serialization proxy pattern the serialization proxy implementation serializing deserializing artificial byte stream examples complexnumber instancecache pros and cons pros lessened extralinguistic character no limitation on final fields flexible instantiation higher security conforms to the single responsibility principle cons unsuited for inheritance possible problems with circular object graphs performance reflection s f share this post with your community i m active on various platforms watch this space or follow me there to get notified when i publish new content in my last post i talked about serialization in general this one is much more focused and presents a single detail the serialization proxy pattern it is a good and often the best way to deal with many of the issues with serialization if there was only one thing a developer would want to know about the topic i d tell them this as far as i know the pattern was first defined in joshua bloch s excellent book effective java 1st edition item 57 2nd edition item 78 this post mostly restates what is said there and focuses on presenting a detailed definition of the pattern before giving two short examples and finally covering the pros and cons the code samples used throughout this post come from a demo project i created on github check it out for more details serialization proxy pattern this pattern is applied to a single class and defines its mechanism of serialization for easier readability the following text will refer to that class or its instances as the original one or ones respectively the serialization proxy as the name suggests the pattern s key is the serialization proxy it is written to the byte stream instead of the original instance after it is deserialized it will create an instance of the original class which takes its place in the object graph me me lic license the goal is to design the proxy such that it is the best possible logical representation of the original class implementation the serializationproxy is a static nested class of the original class all its fields are final and its only constructor has an original instance as its sole argument it extracts the logical representation of that instance s state and assigns it to its own fields as the original instance is considered safe there is no need for consistency checks or defensive copying the original as well as the proxy class implement serializable but since the former is never actually written to the stream only the latter needs a stream unique identifier often called the serial version uid serializing when an original instance is to be serialized the serialization system can be informed to instead write the proxy to the byte stream to do this the original class must implement the following method private object writereplace return new serializationproxy this deserializing on deserialization this translation from original to proxy instance has to be inverted this is implemented in the following method in the serializationproxy which is called after a proxy instance was successfully deserialized private object readresolve create an instance of the original class in the state defined by the proxy s fields creating an instance of the original class will be done via its regular api e g a constructor
|