[jOOQ/jOOQ#8943] Add org.jooq.JSON
This commit is contained in:
parent
18998166bf
commit
29da62058e
85
jOOQ/src/main/java/org/jooq/JSON.java
Normal file
85
jOOQ/src/main/java/org/jooq/JSON.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
/**
|
||||
* A JSON wrapper type for JSON data obtained from the database.
|
||||
*/
|
||||
public final class JSON {
|
||||
|
||||
private final String data;
|
||||
|
||||
private JSON(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static final JSON valueOf(String data) {
|
||||
return new JSON(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((data == null) ? 0 : data.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
JSON other = (JSON) obj;
|
||||
if (data == null) {
|
||||
if (other.data != null)
|
||||
return false;
|
||||
}
|
||||
else if (!data.equals(other.data))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -83,6 +83,7 @@ import java.util.regex.Pattern;
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.JSON;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.UDTRecord;
|
||||
@ -420,9 +421,8 @@ public final class Convert {
|
||||
ConvertAll<T> all = new ConvertAll<>(converter.fromType());
|
||||
List<U> result = new ArrayList<>(collection.size());
|
||||
|
||||
for (Object o : collection) {
|
||||
for (Object o : collection)
|
||||
result.add(convert(all.from(o), converter));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1008,6 +1008,11 @@ public final class Convert {
|
||||
}
|
||||
}
|
||||
|
||||
// [#8943] JSON data types can be read from Strings
|
||||
else if (fromClass == String.class && toClass == JSON.class) {
|
||||
return (U) JSON.valueOf((String) from);
|
||||
}
|
||||
|
||||
// [#3023] Record types can be converted using the supplied Configuration's
|
||||
// RecordMapperProvider
|
||||
else if (Record.class.isAssignableFrom(fromClass)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user