dieselpoint / norm

Access a database in one line of code.
Other
205 stars 36 forks source link

List, serialization question #63

Closed ItsBlockFighter closed 3 years ago

ItsBlockFighter commented 3 years ago

Hi!

Is there a better way to serialize the lists? I do not always want to create a DbSerialization for each data type.

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Group {

    @Id
    @GeneratedValue
    private long id;

    private List<User> users;
}
ccleve commented 3 years ago

Have a look here: https://github.com/dieselpoint/norm#custom-serialization

You might still have to implement a type converter for each type. The system still needs to know how to serialize User. You might be able to implement some common code that works across types to make it easier.

ItsBlockFighter commented 3 years ago

But this still only convert one type. Basically, he's doing the same thing as the former @DbSerializable, @DbSerializer.

ccleve commented 3 years ago

You could have your types implement an interface, maybe something with readFrom() and writeTo() methods, and then create a single converter that handled the interface.