Convert.registerConverter

282 views
Skip to first unread message

fredip...@gmail.com

unread,
Apr 9, 2015, 4:44:15 PM4/9/15
to sq...@googlegroups.com
I'm looking to add some customer converters to a sql2o instance. From what I can tell, Convert.registerConverter is the method to do this, creating a Converter<Class> class and registering it to do the conversion. From looking over the code, this should work.

My concern is that the method is listed as Deprecated, yet there is no obvious replacement. Is this still the way to extend sql2o to handle non-standard classes?

lars....@sonat.no

unread,
Apr 10, 2015, 9:59:52 AM4/10/15
to sq...@googlegroups.com, fredip...@gmail.com
Hi,

There are two ways of registering a converter.
1. 
You can register it through your Quirks class when creating your sql2o instance. Example:
Sql2o sql2o = new Sql2o(myDataSource, new NoQuirks(new HashMap<Class, Converter>() {{
    put(SomeClass.class, new MyConverter());
}}));

This method is preferred if you have connections to multiple databases and you have created a converter that should only be used for one database. This could for example be if you connect both to an Oracle db and a MySql db, and have created a converter for an Oracle specific data type, and you don't want that converter to be mixed with converters used when querying MySql.

2. You can register a converter through the java ServiceLoader functionality. This will register the converter for all instances of Sql2o. This is done by first implementing the ConverterProvider interface and placing a file with filename META-INF/services/org.sql2o.converters.ConvertersProvider that contains the fully qualified name of your ConvertersProvider implementation. For an example on how to do this, checkout how it is done in the Oracle extension.

Leo Miles

unread,
Sep 13, 2025, 12:31:46 PM (6 days ago) Sep 13
to sql2o

A YouTube to MP3 converter is a practical tool that allows users to transform their favorite videos into audio files that can be easily stored and played on any device. It provides a smooth way to convert not just single tracks, but also entire playlists into high-quality MP3 format, ensuring that music, podcasts, or lectures are always accessible. By using such a converter, people can enjoy their content offline, save data while traveling, and create personalized music libraries that fit their lifestyle. This makes it especially useful for those who value convenience, flexibility, and the ability to carry their entertainment anywhere without relying on an internet connection.

Joy White

unread,
Sep 18, 2025, 12:03:38 PM (2 days ago) Sep 18
to sql2o
"The Male Delusion Calculator test is an online tool designed to help men evaluate their perceptions about dating standards and relationship expectations, offering a reality check on how their preferences align with real-world statistics."  
Reply all
Reply to author
Forward
0 new messages