SimpleFlatMapper icon indicating copy to clipboard operation
SimpleFlatMapper copied to clipboard

Add JooqBiConverter to help JooqRecord <-> Java Object custom conversion

Open hank-cp opened this issue 6 years ago • 2 comments

JooqBiConverter should be shared between RecordMapper and RecordUnmapper. It should be helpful to make code more lean and readable.

Usage:

List<JooqBiConverter> converters = new ArrayList<>();
converters.add(new JooqBiConverter<String, JSONObjectTest494.File>() {
	@Override
	public boolean match(Type modelType) {
		return TypeHelper.areEquals(modelType, JSONObjectTest494.File.class);
	}
	@Override
	public JSONObjectTest494.File get(String name, Context context) throws Exception {
		return new JSONObjectTest494.File(0L, name, null);
	}
	@Override
	public String convert(JSONObjectTest494.File file, Context context) throws Exception {
		return file.name;
	}
});

JooqMapperFactory mapperFactory = JooqMapperFactory.newInstance()
		.addBiConverters(converters);

hank-cp avatar Nov 13 '19 18:11 hank-cp

Hidden rule: JooqMapperFactory.addBiConverters() could only be called once. Later converters will override previous added converters. RecordUnmapperBuilder need to be changed to fix this.

hank-cp avatar Nov 14 '19 02:11 hank-cp

might seat on that one for a bit, I think that concept can also be useful in other integrations.

arnaudroger avatar Nov 14 '19 09:11 arnaudroger