Simple Flat Mapper
Release Notes
Getting Started
Docs
Building it
The build is using Maven.
git clone https://github.com/arnaudroger/SimpleFlatMapper.git
cd SimpleFlatMapper
mvn install
The build is using Maven.
git clone https://github.com/arnaudroger/SimpleFlatMapper.git
cd SimpleFlatMapper
mvn install
I was trying to map to a protobuf class - figured out how to create a mapper with an explicit builder, but then when it comes to build the final object, it gets a conflict between the "build" method and the "getDefaultInstanceForType" method. As far as I can see there's no way to explicitly specify the build method in the same way that I specified the instantiator method.
Exception in thread "main" java.lang.IllegalStateException: Duplicate potential build method public com.xyz.MyProto com.xyz.MyProto$Builder.build() and public com.xyz.MyProto com.xyz.MyProto$Builder.getDefaultInstanceForType() at org.simpleflatmapper.reflect.impl.BuilderInstantiatorDefinitionFactory.getDefinitionForBuilder(BuilderInstantiatorDefinitionFactory.java:82) at org.simpleflatmapper.reflect.impl.BuilderInstantiatorDefinitionFactory.getDefinitionForBuilder(BuilderInstantiatorDefinitionFactory.java:60) at org.simpleflatmapper.reflect.ReflectionService.extractInstantiator(ReflectionService.java:206) at org.simpleflatmapper.reflect.meta.ObjectClassMeta.<init>(ObjectClassMeta.java:39) at org.simpleflatmapper.reflect.ReflectionService.getClassMetaExtraInstantiator(ReflectionService.java:153) at org.simpleflatmapper.map.mapper.AbstractMapperFactory.getClassMetaWithExtraInstantiator(AbstractMapperFactory.java:315) at org.simpleflatmapper.map.mapper.AbstractMapperFactory.getClassMetaWithExtraInstantiator(AbstractMapperFactory.java:311) at com.xyz.MyProtoLoader.main(MyProtoLoader.java:50)
Hello,
Im using this kind of mapper :
this.mapper = JdbcMapperFactory
.newInstance()
.addKeys("id")
.discriminator(A.class,
"type",
ResultSet::getString,
builder-> builder.discriminatorCase("TYPEA1", A1.class)
builder-> builder.discriminatorCase("TYPEA2", A2.class)
builder-> builder.discriminatorCase("TYPEA3", A3.class)
builder-> builder.discriminatorCase("TYPEA4", A4.class)
.......
)
.discriminator(B.class,
"b_type",
ResultSet::getString,
builder-> builder.discriminatorCase("TYPEB1", B1.class)
builder-> builder.discriminatorCase("TYPEB2", B2.class)
builder-> builder.discriminatorCase("TYPEB3", B3.class)
builder-> builder.discriminatorCase("TYPEB4", B4.class)
........
)
.newMapper(A.class);
I have a resultset which contains 100K row with 7 columns.
Here is the code mapping rs to list :
String query = "....";
L.info("execute : {}", query);
long start = System.currentTimeMillis();
List objects = new ArrayList();
try (PreparedStatement ps = this.datasource.getConnection().prepareStatement(query);
ResultSet rs = ps.executeQuery()) {
L.info("execute in {} ms", System.currentTimeMillis() - start);
start = System.currentTimeMillis();
objects = mapper.stream(rs).collect(Collectors.toList());
L.info("mapped in {} ms", System.currentTimeMillis() - start);
} catch (SQLException e) {
L.error("impossible to map the result set", e);
}
my timings are : execute in 288 ms mapped in 5103 ms
How can I help you troubleshoot this ?
Hello. I use JdbcMapperFactory with disabled asm (because of issu 457) I have a POJO with structure like:
{
String id;
String name;
List<String> photos;
List<String> videos;
}
And jdbc call which have a few joins and returns ResultSet where potos or videos can have only nulls.
Mapper calls setter for photos and videos if value is null. It could be very annoying as requires additional checks.
I found an issue 445 where this was fixed. But seems only for CsvMapperBuilder and other builders where asm is used and turned on. Also when I checked InstantiatorFactory.java I can see that there is builderBiInstantiator which also has builderIgnoresNullValues flag. But in my case instantiatorDefinition of type CONSTRUCTOR is alway called.
Is there a way to ignor null values with disabled asm?
I failed to find something which can help me in documentation so had to post an issue.
Thank you, Aleksey
When parsing rows that have adjacent commas, indicating a lack of value, the parser throws an error.
Note that I'm running this in Scala so not sure if that's impacting anything.
test.csv
my_field,second_field
,,
class TestClass(var myField: String, var secondField)
val it = CsvParser.mapTo(classOf[TestClass]).iterate(reader)
while(it.hasNext) { println(it.next.myField) }
java.lang.Exception: org.sfm.map.MappingException: Error mapping field org.sfm.csv.CsvColumnKey@3978a417 : null
at io.oseberg.service.bpoocc.CompletionArcgateMasterFileV1ServiceSfm.test(CompletionArcgateMasterFileV1ServiceSfm.scala:41)
... 43 elided
Caused by: org.sfm.map.MappingException: Error mapping field org.sfm.csv.CsvColumnKey@3978a417 : null
at org.sfm.map.impl.RethrowFieldMapperErrorHandler.errorMappingField(RethrowFieldMapperErrorHandler.java:11)
at org.sfm.csv.impl.CsvMapperCellConsumer.newCellForSetter(CsvMapperCellConsumer.java:162)
at org.sfm.csv.impl.CsvMapperCellConsumer.newCell(CsvMapperCellConsumer.java:191)
at org.sfm.csv.impl.CsvMapperCellConsumer.newCell(CsvMapperCellConsumer.java:177)
at org.sfm.csv.parser.AbstractCsvCharConsumer.newCell(AbstractCsvCharConsumer.java:101)
at org.sfm.csv.parser.AbstractCsvCharConsumer.newCellIfNotInQuote(AbstractCsvCharConsumer.java:45)
at org.sfm.csv.parser.StandardCsvCharConsumer.nextRow(StandardCsvCharConsumer.java:41)
at org.sfm.csv.CsvReader.parseRow(CsvReader.java:70)
at org.sfm.csv.impl.CsvMapperIterator.fetch(CsvMapperIterator.java:39)
at org.sfm.csv.impl.CsvMapperIterator.hasNext(CsvMapperIterator.java:31)
I'm talking about this line: https://github.com/arnaudroger/SimpleFlatMapper/blob/e8f193ab649604163023e8fcdb636d00c7fdfa4f/sfm-converter/src/main/java/org/simpleflatmapper/converter/impl/JavaBaseConverterFactoryProducer.java#L183
My use case: I have a lot of enums that will store as int in database but I don't want to use NumberToEnumConverter
because I want to specify the int value explicitly, so i create an interface and have all these enums extends from it and SFM will automatically convert them:
interface IntPersistable {
val persistValue: Int
}
class IntPersistableConverterFactoryProducer : AbstractContextualConverterFactoryProducer() {
override fun produce(consumer: Consumer<in ContextualConverterFactory<*, *>>?) {
factoryConverter<Number, IntPersistable>(consumer, object : AbstractContextualConverterFactory<Number, IntPersistable>(Number::class.java, IntPersistable::class.java) {
override fun newConverter(targetedTypes: ConvertingTypes, contextFactoryBuilder: ContextFactoryBuilder,
vararg params: Any): ContextualConverter<in Number, out IntPersistable> {
@Suppress("UNCHECKED_CAST")
return IntPersistableConverter(targetedTypes.to as Class<IntPersistable>)
}
})
}
}
However this doesn't work because the EnumConverterFactory's score is higher than my factory. So as a workaround I have to override the score to return the MAX_VALUE on source too (which is a dirty workaround for no reason..?)
override fun score(targetedTypes: ConvertingTypes): ConvertingScore {
return if (TypeHelper.isAssignable(IntPersistable::class.java, targetedTypes.to)) {
ConvertingScore(ConvertingScore.MAX_SCORE, ConvertingScore.MAX_SCORE)
} else {
super.score(targetedTypes)
}
}
The NumberToEnumConverter
is a convenient generic class so it shouldn't have max score that override user's other implementation class right?
My second issue is that I don't understand why ConvertingTypes when calculating the target score it calls the TypeHelper.isAssignable(target, from)
? Shouldn't it be the other way around as TypeHelper.isAssignable(from, target)
as it need to check if the targeted type can assign to the specified class/interface? (Or i'm using the whole thing wrongly?)
https://github.com/arnaudroger/SimpleFlatMapper/blob/d54829134b008c3a341ceabdd7b51cbeeb4b6787/sfm-converter/src/main/java/org/simpleflatmapper/converter/ConvertingTypes.java#L72
PS. Sorry for Kotlin, i'm too lazy to convert to Java but you should get the idea
It would be nice if the parser would provide the ability to skip commented lines but store commented line and return it on demand, e.g. by calling reader.getLastComment().
Hi,
I have a CSV file with this header:
Patientennummer;Matchcode;Firma;Anrede;Titel;Name;Anschrift;Land;Briefanrede;Behandelt;Telefon1;Telefon2;Telefax;Mobil;Email1;Email2;Geschlecht;Geboren;Datum;Geändert;R_Geboren;Kontoinhaber;Bank;Konto;BLZ;IBAN;BIC;Internet;PatNr;R_Firma1;R_Anrede;R_Titel;R_Name;R_Anschrift;R_Land;R_Briefanrede;Beruf;Familienstand;Größe;Gewicht;Bemerkung;Diagnose;Anamnese;Hinweis;Versicherung;Risikofaktoren;Allergien;Unfälle;Operationen;Dauertherapie;Versicherer;Zahlungsziel;
And I am trying to parse using:
CsvParser .separator(';') .mapTo(SmedPatient.class) .defaultHeaders() .stream(isr) .forEach(p -> { repo.getPatienten().put(p.parsedPatientNummer(), p); });
I have the property annotated as following:
@Column(name="Geändert") private String geaendert;
What am I doing wrong? Is it the umlauts?
Hi,
After a very long delay (sorry), I'm finally investigating switching from Jackson's jackson-dataformat-csv to sfm-csv.
Sadly, I hit a major blocker: IMHO, sfm-csv escaping support is broken.
sfm-csv confuses quoteChar
and escapeChar, those are 2 different things (at least, they are in Jackson, and it makes sense).
quoteChar
(typically "
) is to wrap values, so chars inside the wrapped String are not handled as separator
, eg "foo;bar";"baz"
escapeChar
(typically \
) is to escape following char so it is not handled as a special one (separator
, quoteChar
and escapeChar
itself), eg "foo\"bar\"baz"
Sadly, this doesn't work as expected as they are considered the same thing (https://github.com/arnaudroger/SimpleFlatMapper/blob/master/sfm-csv/src/main/java/org/simpleflatmapper/csv/CsvParser.java#L547 and https://github.com/arnaudroger/SimpleFlatMapper/blob/master/sfm-csv/src/main/java/org/simpleflatmapper/csv/parser/TextFormat.java#L9), eg: "foo\"bar\"baz"
:
foo"bar"baz
foo\bar\baz
Regards
I have an enum like this:
public enum MyEnum {
DESCRIPTIVE_NAME1("short_code1"),
DESCRIPTIVE_NAME2("short_code2"),
...
MyEnum(String shortCode) {
this.shortCode = shortCode;
}
...
public static MyEnum fromShortCode(String shortCode) {
// lookup from MyEnum.values() using shortCode
}
}
And a class with MyEnum
field. The corresponding table column holds shortCode
values. Is there a way to use MyEnum.fromShortCode()
when reading the value from the result set? Right now anything I do doesn't seem to have an effect and org.simpleflatmapper.converter.impl.CharSequenceToEnumConverter.convert()
gets called no matter what. This of course calls java.lang.Enum.valueOf()
and mapping fails.
I use SFM with JdbcTemplate and tried using both JdbcTemplateMapperFactory.addColumnDefinition()
and the ServiceLoader/Converter approach.
Any working example on how to achieve this? I imagine this is a fairly common use case, since other libraries like Jackson provide a special way to serialize/deserialize enums not only by their name.
I read your page about the integration with sql2o, but I didn't understand the advantages.
For what I know sql2o do support inner objects, and I don't understand what you mean with factory and joins.
Can someone explain me?
When using JOOQ and using .fetch().intoResultSet() instead of .fetchResultSet() I get an exception:
java.lang.IllegalStateException: No date format specified at org.simpleflatmapper.converter.impl.time.JavaTimeHelper.getDateTimeFormatters(JavaTimeHelper.java:56) at org.simpleflatmapper.converter.impl.time.AbstractMultiFormatContextualConverterFactory.newConverter(AbstractMultiFormatContextualConverterFactory.java:20) at org.simpleflatmapper.converter.ConverterService.findConverter(ConverterService.java:90) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.lookForAlternativeGetter(ConstantSourceFieldMapperFactoryImpl.java:272) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.getGetterFromSource(ConstantSourceFieldMapperFactoryImpl.java:249) at org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapperFactoryImpl.newFieldMapper(ConstantSourceFieldMapperFactoryImpl.java:195) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder.newFieldMapper(DefaultConstantSourceMapperBuilder.java:920) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder$PropertyFieldMeta.targetFieldMapper(DefaultConstantSourceMapperBuilder.java:757) at org.simpleflatmapper.map.mapper.DefaultConstantSourceMapperBuilder.targetFieldMappers(DefaultConstantSourceMapperBuilder.java:649)...
If I use the normal .fetchResultSet() way everything works.
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 696/1000
Why? Recently disclosed, Has a fix available, CVSS 8.2 | HTTP Response Splitting
SNYK-JAVA-IONETTY-3167773 | com.datastax.cassandra:cassandra-driver-core:
3.7.1 -> 4.0.0
| Yes | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
🦉 Learn about vulnerability in an interactive lesson of Snyk Learn.
This PR was automatically created by Snyk using the credentials of a real user.
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 661/1000
Why? Recently disclosed, Has a fix available, CVSS 7.5 | Denial of Service (DoS)
SNYK-JAVA-COMGOOGLEPROTOBUF-3167772 | mysql:mysql-connector-java:
8.0.16 -> 8.0.31
| No | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 661/1000
Why? Recently disclosed, Has a fix available, CVSS 7.5 | Denial of Service (DoS)
SNYK-JAVA-COMGOOGLEPROTOBUF-3167772 | com.google.protobuf:protobuf-java:
3.6.1 -> 3.16.3
| No | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
This PR was automatically created by Snyk using the credentials of a real user.
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 521/1000
Why? Recently disclosed, Has a fix available, CVSS 4.7 | Information Exposure
SNYK-JAVA-ORGPOSTGRESQL-3146847 | org.postgresql:postgresql:
42.2.5 -> 42.2.27
| No | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
🦉 Learn about vulnerability in an interactive lesson of Snyk Learn.
This PR was automatically created by Snyk using the credentials of a real user.
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 686/1000
Why? Recently disclosed, Has a fix available, CVSS 8 | Remote Code Execution (RCE)
SNYK-JAVA-ORGHSQLDB-3040860 | org.hsqldb:hsqldb:
2.4.0 -> 2.7.1
| No | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
This PR was automatically created by Snyk using the credentials of a real user.
Severity | Priority Score (*) | Issue | Upgrade | Breaking Change | Exploit Maturity
:-------------------------:|-------------------------|:-------------------------|:-------------------------|:-------------------------|:-------------------------
| 571/1000
Why? Recently disclosed, Has a fix available, CVSS 5.7 | Denial of Service (DoS)
SNYK-JAVA-COMGOOGLEPROTOBUF-3040284 | mysql:mysql-connector-java:
8.0.16 -> 8.0.31
| No | No Known Exploit
(*) Note that the real score may have changed since the PR was raised.
Check the changes in this PR to ensure they won't cause issues with your project.
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.
For more information: 🧐 View latest project report
📚 Read more about Snyk's upgrade and patch logic
Learn how to fix vulnerabilities with free interactive lessons:
Hibernate ORM is a library providing Object/Relational Mapping (ORM) support to applications, libraries, and frameworks. It also provides an implement
Doma Doma 2 is a database access framework for Java 8+. Doma has various strengths: Verifies and generates source code at compile time using annotatio
MyBatis SQL Mapper Framework for Java The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented applications.
Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation
About ORM16 ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model. Example I
ObjectiveSQL is an ORM framework in Java based on ActiveRecord pattern, which encourages rapid development and clean, codes with the least, and convention over configuration.
Ebean ORM
Spring Boot One To Many example with Spring JPA, Hibernate Implement Spring JPA One-To-Many mapping with Hibernate in a Spring Boot CRUD example using
Permazen is a better persistence layer for Java Persistence is central to most applications. But there are many challenges involved in persistence pro
LightORM A lightweight and performant Java ORM alternative. LightORM has annotation processors so that all the integration code with the database is g
beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple
SpringMVC-Database-Integration This module explains about the example of Spring MVC + Database Integration with MySQL using Hibernate ORM with practic
Mars Object Relational Mapping Framework for MongoDB 致自己 造自己的轮子,让别人去说 ; What is Mars Mars is a unified driver platform product developed by Shanghai J
A stupidly simple Java/MySQL ORM with native Hikaricp and Redis cache support supporting MariaDB and Sqlite
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ
Hibernate ORM is a library providing Object/Relational Mapping (ORM) support to applications, libraries, and frameworks. It also provides an implement
University Management In this project, I practiced & applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, P
RatORM Simple, Fast and easy to implement ORM for most popular databases Status: Branch Tests Code Quality master Usefull links Helpful links: GitHub
Snap-Snippet A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture. Tech
Dozer Active Contributors We are always looking for more help. The below is the current active list: Core @garethahealy @orange-buffalo ?? Protobuf @j