-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
missing custom casting #12
Comments
I haven't seen that sort of query before. What type of object does jdbc normally give you? What database? |
FYI, automap just maps resultset columns to obviously transformable types (like BigInteger to long). Looks like you are getting an interesting type back that I'm not familiar with. |
is postgresql database ..basicaly that query just return a string in json format ..tested and it works ..but i get the error ClassCastException: java.lang.String cannot be cast to CUSTOMTYPE |
is there any way i can make automap to use custom converters .. or maybe be able to declare some custom converters ? |
Ok then you map to a string value in that class and do another .map to convert the string to a json object using Jackson or whatever. Why would this library be in the business of parsing json? |
Happy to give example if needed |
cause i happen to already mix json in the process : like this ... public interface CUSTOMTYPE {
} |
Maybe i am out of line here. but it would have been nice if along with annotation would be possible to have custom casting of fields or posibility of declaring and using converters from sql field types to desired object type... |
something like |
Yep I see what you mean and not hard to do. I'll have a look. I'll get that
example to you a bit later (about to catch a flight).
…On Sun, 17 Dec. 2017, 11:34 sorinpepelea, ***@***.***> wrote:
something like
@column <https://github.com/column>("A")
@converter <https://github.com/converter>(CustomConverter.class)
CUSTOMTYPE getA();
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AATa6wdkbZ3lSZNssQ7atmev33z1Zj5oks5tBGGMgaJpZM4REfvt>
.
|
I've had an initial look and the converter annotation idea is not very attractive because you lose type safety with the annotation (in your example above we can't ensure that My suggestion at the moment is you handle your own mapping to the custom types: @Query("select '{"X":1, "Y":2}'::json "A";")
public interface Holder {
@Column("A")
String getA();
}
public static final class Parsed {
public final int x;
public final y;
Parsed(int x, int y) {
this.x = x;
this.y = y;
}
}
//use it
db.select(Holder.class)
.map(holder -> JsonParser.parse(holder.a()))
.map(json -> new Parsed(json.getInt("X"), json.getInt("Y")))
.blockingForEach(System.out::println); |
thanks class CustomConvertor implements DefaultConvertor { ... maping rules from java.sql.type to customtype type}@interface Convertor {Class value = ...}public interface TEST { |
idk if this can be classified as an issue but i have problem casting string to a custom class in automaping
i see no option in automap example to cast string field to customclass
example below
db.select(TEST.class)
.get()
.subscribe(
E -> System.out.println(E.getA())
).dispose();
deffinition of TEST interface :
@query("select '{"X":1, "Y":2}'::json "A";")
public interface TEST {
}
deffinition of CUSTOMTYPE interface :
public interface CUSTOMTYPE {
}
The text was updated successfully, but these errors were encountered: