Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
= Changelog

== v2.5.4 (work in progress)


=== New features and improvements

- https://github.com/eclipse-sirius/sirius-emf-json/issues/70[#70] Improve custom data types support


== v2.5.3


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.InvalidParameterException;
import java.text.SimpleDateFormat;
import java.util.Collection;
Expand All @@ -33,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -993,59 +996,57 @@ private JsonElement serializeEAttribute(EObject eObject, EAttribute eAttribute)
JsonElement value = null;
EClassifier eType = eAttribute.getEType();

if (EcorePackage.eINSTANCE.getEString().equals(eType)) {
value = this.serializeEStringEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEBoolean().equals(eType)) {
value = this.serializeEBooleanEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEBooleanObject().equals(eType)) {
value = this.serializeEBooleanEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEInt().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEIntegerObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEBigDecimal().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEBigInteger().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEByte().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEByteArray().equals(eType)) {
value = this.serializeEByteArrayEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEByteObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEChar().equals(eType)) {
value = this.serializeEStringEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getECharacterObject().equals(eType)) {
value = this.serializeEStringEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEDate().equals(eType)) {
value = this.serializeEDateEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEDouble().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEDoubleObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEFloat().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEFloatObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getELong().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getELongObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEShort().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEShortObject().equals(eType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (eType instanceof EEnum) {
if (eType instanceof EEnum) {
value = this.serializeEEnumEAttribute(eObject, eAttribute);
} else if (eType instanceof EDataType) {
value = this.serializeEDataType(eObject, eAttribute);
} else if (eType instanceof EDataType eDataType) {
if (this.isStringType(eDataType)) {
value = this.serializeEStringEAttribute(eObject, eAttribute);
} else if (this.isNumberType(eDataType)) {
value = this.serializeENumberEAttribute(eObject, eAttribute);
} else if (this.isBooleanType(eDataType)) {
value = this.serializeEBooleanEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEByteArray().equals(eDataType)) {
value = this.serializeEByteArrayEAttribute(eObject, eAttribute);
} else if (EcorePackage.eINSTANCE.getEDate().equals(eDataType)) {
value = this.serializeEDateEAttribute(eObject, eAttribute);
} else {
value = this.serializeEDataType(eObject, eAttribute);
}
} else {
throw new InvalidParameterException();
}

return value;
}

private boolean isStringType(EDataType type) {
return Objects.equals(type.getInstanceClassName(), String.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Character.class.getName()) ||
Objects.equals(type.getInstanceClassName(), char.class.getName());
}

private boolean isNumberType(EDataType type) {
return Objects.equals(type.getInstanceClassName(), Long.class.getName()) ||
Objects.equals(type.getInstanceClassName(), long.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Integer.class.getName()) ||
Objects.equals(type.getInstanceClassName(), int.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Short.class.getName()) ||
Objects.equals(type.getInstanceClassName(), short.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Byte.class.getName()) ||
Objects.equals(type.getInstanceClassName(), byte.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Double.class.getName()) ||
Objects.equals(type.getInstanceClassName(), double.class.getName()) ||
Objects.equals(type.getInstanceClassName(), Float.class.getName()) ||
Objects.equals(type.getInstanceClassName(), float.class.getName()) ||
Objects.equals(type.getInstanceClassName(), BigInteger.class.getName()) ||
Objects.equals(type.getInstanceClassName(), BigDecimal.class.getName());
}

private boolean isBooleanType(EDataType type) {
return Objects.equals(type.getInstanceClassName(), Boolean.class.getName()) ||
Objects.equals(type.getInstanceClassName(), boolean.class.getName());
}

/**
* Returns the JsonElement representing an EDataType.
*
Expand Down
Loading