Failed to map postgresql timestamp to timezone in camel jdbc

I have the following route that gets data from postgresql, but the date object goes null. he cannot match this value

My route, if you follow

<route id="instrumentqueryshortsell">
        <from uri="direct:restinstumentshortsell"/>
        <bean ref="inConverter" method="convert"/>
        <setBody>
            <simple>select instrumentId as instrument_Id ,amount,easytoborrow as easy_To_Borrow,hardtoborrow as hard_To_Borrow ,datetime as date from instrument_short_sell where instrumentId in (${body}) </simple>
        </setBody>
        <log message="Running following query ${body} " loggingLevel="DEBUG"/>
        <to uri="jdbc:dataSource?useHeadersAsParameters=true&amp;outputClass=<packagename?.InstrumentShortSell" />

    </route>

My Pojo class looks like

import java.time.LocalDateTime;

import org.joda.time.DateTime;


public class InstrumentShortSell {

    private String instrumentId;
    private long amount;
    private boolean easyToBorrow;
    private boolean hardToBorrow;
    private DateTime date;

    public DateTime getDate() {
        return date;
    }
    public void setDate(DateTime date) {
        this.date = date;
    }
    public String getInstrumentId() {
        return instrumentId;
    }
    public void setInstrumentId(String instrumentId) {
        this.instrumentId = instrumentId;
    }
    public long getAmount() {
        return amount;
    }
    public void setAmount(long amount) {
        this.amount = amount;
    }
    public boolean isEasyToBorrow() {
        return easyToBorrow;
    }
    public void setEasyToBorrow(boolean easyToBorrow) {
        this.easyToBorrow = easyToBorrow;
    }
    public boolean isHardToBorrow() {
        return hardToBorrow;
    }
    public void setHardToBorrow(boolean hardToBorrow) {
        this.hardToBorrow = hardToBorrow;
    }


}

SQl Scheme

CREATE TABLE instrument_short_sell (
    instrumentId serial ,
    amount INTEGER,
    easytoborrow boolean,
    hardtoborrow boolean,
    datetime timestamp with time zone
) ;

I cannot match jodadatetime and every time it becomes null. Please help me how can we match this on jdbc camel

+4
source share
1 answer

You need to add a type converter for org.joda.time.DateTime, so that Camel can convert the string value to a joda time instance. Camel does not come with these converters out of the box.

java.lang.Object POJO .

+2

Source: https://habr.com/ru/post/1691172/


All Articles