1

I am using Immutables and I configure my generated class to be instantiated through a constructor.

@Gson.TypeAdapters
@Value.Immutable(builder = false)
@Value.Style(
        of = "new",
        allParameters = true,
        get = {"get*", "is*"})
public interface MyClass {
  String getX();
  boolean isGreen();
}

However now instances are serialized as tuples as specified in https://immutables.github.io/json.html#tuples-of-constructor-arguments

    ["someValueOfX", true]

Instead I require the same serialization as when I use builder instead of constructor

    {
      "x" : "someValueOfX",
      "green" : true
    }

Is it possible to disable serialization into tuple?

Dennis
  • 646
  • 2
  • 6
  • 19

1 Answers1

1

It looks like that format switch is an intentional side effect you get by using builder=false - from the link:

In order to marshal object as tuple, you need to annotate constructor arguments and disable generation of builders

I agree it's awkward to couple builder existence to serialization format, but it seems that's the only way... so the best approach to get your desired serialization format is just to remove builder=false.

Krease
  • 15,805
  • 8
  • 54
  • 86