-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Fix DbClient JSON mapping (#7844)
- DbColumn.get() overrides Value.get() using as() instead of as().get() thus it returns an instance of Value instead of the raw value. - Add a unit test in dbclient/jsonp Fixes #7842
- Loading branch information
1 parent
73e9579
commit 75e0e95
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
dbclient/jsonp/src/test/java/io/helidon/dbclient/jsonp/JsonProcessingMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.helidon.dbclient.jsonp; | ||
|
||
import io.helidon.common.mapper.MapperManager; | ||
import io.helidon.dbclient.DbColumn; | ||
import io.helidon.dbclient.DbColumnBase; | ||
import io.helidon.dbclient.DbMapperManager; | ||
import io.helidon.dbclient.DbRow; | ||
import io.helidon.dbclient.DbRowBase; | ||
|
||
import jakarta.json.JsonObject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
/** | ||
* Tests {@link io.helidon.dbclient.jsonp.JsonProcessingMapper}. | ||
*/ | ||
class JsonProcessingMapperTest { | ||
|
||
private static final DbMapperManager DB_MAPPER_MANAGER = DbMapperManager.builder() | ||
.addMapperProvider(new JsonProcessingMapperProvider()) | ||
.build(); | ||
|
||
@Test | ||
void testRowAsJsonObject() { | ||
DbRow row = row(column("foo", "bar"), column("bob", "alice")); | ||
JsonObject jsonObject = row.as(JsonObject.class); | ||
assertThat(jsonObject.getString("foo"), is("bar")); | ||
} | ||
|
||
private static DbRow row(DbColumnBase... columns) { | ||
return new DbRowBase(columns, DB_MAPPER_MANAGER) { | ||
@Override | ||
public DbColumn column(String name) { | ||
return super.column(name); | ||
} | ||
}; | ||
} | ||
|
||
private static DbColumnBase column(String name, Object value) { | ||
return new DbColumnBase(value, MapperManager.create()) { | ||
|
||
@Override | ||
public Class<?> javaType() { | ||
return value.getClass(); | ||
} | ||
|
||
@Override | ||
public String dbType() { | ||
return "test"; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
}; | ||
} | ||
} |