example-postgresql icon indicating copy to clipboard operation
example-postgresql copied to clipboard

Deserilization to type String

Open quijos12 opened this issue 3 years ago • 1 comments

I have added the column 'created' to the table 'AppUser' in the example-postgresql

CREATE TABLE IF NOT EXISTS AppUser (
    id                      varchar (256) PRIMARY KEY,
    username                varchar (256) NOT NULL,
    email                   varchar (256) NOT NULL,
    password                varchar (256) NOT NULL,
    role                    varchar (256) NULL,
    created                 timestamp DEFAULT now(), -- NEW COLUMN --
    CONSTRAINT              UK_APPUSER_USERNAME UNIQUE (username),
    CONSTRAINT              UK_APPUSER_EMAIL UNIQUE (email)
);

I have modified 'UserDto.hpp' to add the field as String DTO_FIELD(String, created, "created");

but when I try to test the endpoint of getUserById to select some user, I get the following error

{
  "status": "ERROR",
  "code": 500,
  "message": "[oatpp::postgresql::mapping::Deserializer::deserializeString()]: Error. Unknown OID."
}

as I understand from the error message I have to perform a conversion type to take the timestamp value to string

How can I do this?

quijos12 avatar Feb 07 '22 15:02 quijos12

Hello @Quijos12 ,

You have to cast timestamp to string on PostgreSQL side, before returning DB result.

Please see this StackOverflow answer - https://stackoverflow.com/questions/15990344/select-date-timestamp-from-postgresql-as-string-char-beware-of-null-value

lganzzzo avatar Feb 07 '22 15:02 lganzzzo