Questions tagged [java-custom-serialization]

Customize the Default Protocol - Serialization

This is interesting feature of Java Serialization which allow a developer to customize the serialization process in Serializable class.

Reference Article : Discover the secrets of the Java Serialization API

19 questions
15
votes
4 answers

Can we deny a java object from serialization other than giving transient keyword

We can avoid serialising fields by using the transient keyword. Is there any other way of doing that?
Biju CD
  • 4,999
  • 11
  • 34
  • 55
3
votes
1 answer

Why is the ArrayList size field not transient?

Java's ArrayList uses custom serialization and explicitly writes the size. Nevertheless, size is not marked in ArrayList as transient. Why is size written two times: once via defaultWriteObject and again vis writeInt(size) as shown below…
Jonathan
  • 1,349
  • 1
  • 10
  • 20
3
votes
2 answers

Custom Serialization using ReadObject and WriteObject

I am trying to write a instance of pojo class by using WriteObject method. when i write code like this : private void writeObject(ObjectOutputStream oos) throws IOException,ClassNotFoundException{ oos.defaultWriteObject(); …
3
votes
1 answer

How do writeObject and readObject work?

When I read the source code of JDK 6.0 I found these two methods in ArrayList. You see they are both private. But after searching, I didn't find any other methods calling either of them. I also considered the native methods, but still couldn't find…
blackdog
  • 2,007
  • 3
  • 25
  • 43
2
votes
1 answer

Custom BeanPropertyFilter - only serializing part of string

I am in dire need of help. I am currently making some security restrictions on a resource in a Content API, where i need to either: Include properties, Truncate properties (if they are String.class) or remove properties from the object of…
Martin Hansen
  • 2,033
  • 1
  • 18
  • 34
1
vote
3 answers

Jackson custom serializer with null values to be suppressed

I have a custom serializer to treat String with blank values as null and also to trim trailing blank spaces. Follwoing is the code for the same. - public class StringSerializer extends JsonSerializer { @Override public void…
0
votes
0 answers

Not able to serialize nested object with custon jackson parser

I have created a custom serializer for my java class, Which contains the many nested objects. My motive is to add the type of the java class in the serialized JSON object. ex My class type is Student and JSON created is { id:1, name:abc } I want to…
Shivank
  • 95
  • 1
  • 1
  • 5
0
votes
1 answer

How to set a custom serializer to ever API endpoint (spring app) with a specific annotation?

let's say I have a controller with an endpoint. @controller public class booksController{ @SomeCustomAnnotation public String getBookOnlyName(){ return new book(); } public String getBookAllData(){ return new book(); } } In…
0
votes
1 answer

How to serialize an object which it's method has multiple parameters

I'm a beginner to java and I need help. I have two classes, one (Song) see code is a Child of the second one (Date). Song is serializeable while Date is not serializeable (and i intend to keep the Date class that way). I'm using method from Date…
RhinoPak
  • 21
  • 6
0
votes
1 answer

json serializer with spring boot

I have BigDecimalSerializer public class BigDecimalSerializer extends JsonSerializer { @Override public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException…
Shahid Ghafoor
  • 2,991
  • 17
  • 68
  • 123
0
votes
0 answers

Change attribute name dynamically Gson while Serialization

I've got MultivaluedMap of custom object types which I am serializing using Gson. One of my requirement is to change the name of one of the object based on the length of the string to some other name. I know that we can use annotations…
Panibhat
  • 1
  • 1
0
votes
0 answers

how to set Hibernate L2 cache with Hazelcast for two different apps, with different packages` names and Entity names

I am using Hazelcast as 2L cache provider for hibernate. My problem is that im trying to use Portable serialization, but by default when Application works it uses CacheKeyImpl class from hazelcast.hibernate.region package for Key serialization. How…
0
votes
2 answers

How to configure List type in hazelcast-client.xml for custom Byte array serialization

I have created a custom serialization class using ByteArraySerializer as follows. public class ProgramListSerializer implements ByteArraySerializer> { public static final TypeReference> LIST_PROGRAM_TYPE = new…
0
votes
1 answer

Create a json deserializer and use it

How do you create a jackson custom serializer and use it in your program? The serializer is used to serialize data from a kafka stream, because my job fails if it encounters a null. I tried the following to create a serializer. import…
Srinivas
  • 2,010
  • 7
  • 26
  • 51
0
votes
1 answer

Difference between custom serialisation and Externalisation?

Recently from any source, I came to know that custom serialisation is a process where we can define writeObject(ObjectOutputStream os) and readObject(ObjectInputStream is) in our Serializable class, and these methods will be executed at the time of…
1
2