private String unwrapSource(String iSource) { if (iSource == null) throw new OSerializationException("Error on unmarshalling JSON content: content is null"); iSource = iSource.trim(); if (!iSource.startsWith("{") || !iSource.endsWith("}")) throw new OSerializationException("Error on unmarshalling JSON content '" + iSource + "': content must be between { }"); iSource = iSource.substring(1, iSource.length() - 1).trim(); return iSource; }
@Override public ODocument convertToObject(String value, Locale locale) throws ConversionException { value = value.trim(); if(value.startsWith("{")) { try { ODocument doc = new ODocument(); return doc.fromJSON(value, true); } catch (OSerializationException e) { throw newConversionException("Cannot convert '" + value + "' to "+getTargetType().getSimpleName()+": "+e.getMessage(), value, locale); } } else return convertToOIdentifiable(value, locale).getRecord(); }
record = ORecordSerializerJSON.INSTANCE.fromString(value, record, null); } catch (OSerializationException e) { if (e.getCause() instanceof OSchemaException) {
@Override public ODocument convertToObject(String value, Locale locale) throws ConversionException { value = value.trim(); if(value.startsWith("{")) { try { ODocument doc = new ODocument(); return doc.fromJSON(value, true); } catch (OSerializationException e) { throw newConversionException("Cannot convert '" + value + "' to "+getTargetType().getSimpleName()+": "+e.getMessage(), value, locale); } } else return convertToOIdentifiable(value, locale).getRecord(); }
private byte[] bytesFromString(final String toWrite) { try { return toWrite.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string encoding"), e); } }
protected static byte[] bytesFromString(final String toWrite) { try { return toWrite.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string encoding"), e); } }
protected String stringFromBytes(final byte[] bytes, final int offset, final int len) { try { return new String(bytes, offset, len, CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string decoding"), e); } }
protected String stringFromBytes(final byte[] bytes, final int offset, final int len) { try { return new String(bytes, offset, len, CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string decoding"), e); } }
private byte[] bytesFromString(final String toWrite) { try { return toWrite.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string encoding"), e); } }
private byte[] bytesFromString(final String toWrite) { try { return toWrite.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string encoding"), e); } }
protected String stringFromBytes(final byte[] bytes, final int offset, final int len) { try { return new String(bytes, offset, len, CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string decoding"), e); } }
protected static String stringFromBytes(final byte[] bytes, final int offset, final int len) { try { return new String(bytes, offset, len, CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error on string decoding"), e); } }
/** * Serialize the class name size + class name + object content * * @param iValue */ public StringBuilder toStream(final StringBuilder iOutput, Object iValue) { if (iValue != null) { if (!(iValue instanceof OSerializableStream)) throw new OSerializationException("Cannot serialize the object since it's not implements the OSerializableStream interface"); OSerializableStream stream = (OSerializableStream) iValue; iOutput.append(iValue.getClass().getName()); iOutput.append(OStringSerializerEmbedded.SEPARATOR); iOutput.append(Base64.getEncoder().encodeToString(stream.toStream())); } return iOutput; }
private Object getValueAsMap(ODocument iRecord, String iFieldValue, OType iLinkedType, Map<String, Character> iFieldTypes, boolean iNoMap, String iOptions, String[] fields) { if (fields.length % 2 == 1) throw new OSerializationException("Bad JSON format on map. Expected pairs of field:value but received '" + iFieldValue + "'"); final Map<String, Object> embeddedMap = new LinkedHashMap<String, Object>(); for (int i = 0; i < fields.length; i += 2) { String iFieldName = fields[i]; if (iFieldName.length() >= 2) iFieldName = iFieldName.substring(1, iFieldName.length() - 1); iFieldValue = fields[i + 1]; final String valueAsString = OIOUtils.getStringContent(iFieldValue); embeddedMap.put(iFieldName, getValue(iRecord, null, iFieldValue, valueAsString, iLinkedType, null, iFieldTypes, iNoMap, iOptions)); } return embeddedMap; }
/** * Serialize the class name size + class name + object content */ public StringBuilder toStream(final StringBuilder iOutput, Object iValue) { if (iValue != null) { if (iValue instanceof ODocumentSerializable) iValue = ((ODocumentSerializable) iValue).toDocument(); if (!(iValue instanceof OSerializableStream)) throw new OSerializationException( "Cannot serialize the object since it's not implements the OSerializableStream interface"); OSerializableStream stream = (OSerializableStream) iValue; iOutput.append(iValue.getClass().getName()); iOutput.append(SEPARATOR); try { iOutput.append(new String(stream.toStream(), "UTF-8")); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error serializing embedded object"), e); } } return iOutput; }
public static String mapToJSON(final Map<?, ?> iMap, final String iFormat, final StringBuilder buffer) { try { buffer.append('{'); if (iMap != null) { int i = 0; Entry<?, ?> entry; for (Iterator<?> it = iMap.entrySet().iterator(); it.hasNext(); ++i) { entry = (Entry<?, ?>) it.next(); if (i>0) buffer.append(","); buffer.append(writeValue(entry.getKey(), iFormat)); buffer.append(":"); buffer.append(writeValue(entry.getValue(), iFormat)); } } buffer.append('}'); return buffer.toString(); } catch (IOException e) { throw OException.wrapException(new OSerializationException("Error on serializing map"), e); } }
public final int setCustom(final String iContent) { try { return set(iContent.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("error encoding string"),e); } }
public byte[] writeClassOnly(ORecord iSource) { final ODocument record = (ODocument) iSource; StringBuilder iOutput = new StringBuilder(); if (ODocumentInternal.getImmutableSchemaClass(record) != null) { iOutput.append(ODocumentInternal.getImmutableSchemaClass(record).getStreamableName()); iOutput.append(OStringSerializerHelper.CLASS_SEPARATOR); } try { return iOutput.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("error writing class name"), e); } }
throw new OSerializationException("Object not supported: " + object);
/** * Fills the ODocument directly with the string representation of the document itself. Use it for faster insertion but pay * attention to respect the OrientDB record format. <p> <code> record.reset();<br> record.setClassName("Account");<br> * record.fromString(new String("Account@id:" + data.getCyclesDone() + ",name:'Luca',surname:'Garulli',birthDate:" + * date.getTime()<br> + ",salary:" + 3000f + i));<br> record.save();<br> </code> </p> * * @param iValue String representation of the record. */ @Deprecated public void fromString(final String iValue) { _dirty = true; _contentChanged = true; try { _source = iValue.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSerializationException("Error reading content from string"), e); } removeAllCollectionChangeListeners(); _fields = null; _fieldSize = 0; }