CcmNG: Fix

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5664 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2018-08-08 17:18:28 +00:00
parent 50ccf39227
commit 997644d119
1 changed files with 33 additions and 20 deletions

View File

@ -296,14 +296,15 @@ public class Components {
final ComponentModel componentModel) { final ComponentModel componentModel) {
final Class<? extends ComponentModel> clazz = Objects final Class<? extends ComponentModel> clazz = Objects
.requireNonNull(componentModel.getClass()); .requireNonNull(componentModel)
.getClass();
final ComponentModelJsonConverter jsonConverter final ComponentModelJsonConverter jsonConverter
= findJsonConverter(clazz) = findJsonConverter(clazz)
.orElseThrow(() -> new WebApplicationException(String.format( .orElseThrow(() -> new WebApplicationException(String.format(
"No JSON converter available for component model \"%s\".", "No JSON converter available for component model \"%s\".",
clazz.getName()))); clazz.getName())));
return jsonConverter.toJson(componentModel); return jsonConverter.toJson(componentModel);
// Objects.requireNonNull(componentModel); // Objects.requireNonNull(componentModel);
@ -394,9 +395,9 @@ public class Components {
try { try {
componentModel = clazz.getConstructor().newInstance(); componentModel = clazz.getConstructor().newInstance();
} catch (IllegalAccessException } catch (IllegalAccessException
| InstantiationException | InstantiationException
| InvocationTargetException | InvocationTargetException
| NoSuchMethodException ex) { | NoSuchMethodException ex) {
throw new WebApplicationException(ex); throw new WebApplicationException(ex);
} }
@ -453,19 +454,31 @@ public class Components {
final JsonObject data, final JsonObject data,
final ComponentModel componentModel) { final ComponentModel componentModel) {
final BeanInfo beanInfo; final Class<? extends ComponentModel> clazz = Objects
try { .requireNonNull(componentModel)
beanInfo = Introspector.getBeanInfo(componentModel.getClass()); .getClass();
} catch (IntrospectionException ex) {
throw new WebApplicationException(ex);
}
Arrays final ComponentModelJsonConverter jsonConverter
.stream(beanInfo.getPropertyDescriptors()) = findJsonConverter(clazz)
.forEach( .orElseThrow(() -> new WebApplicationException(String.format(
propertyDesc -> setComponentPropertyFromJson(componentModel, "No JSON converter available for component model \"%s\".",
propertyDesc, clazz.getName())));
data));
jsonConverter.fromJson(data, componentModel);
// final BeanInfo beanInfo;
// try {
// beanInfo = Introspector.getBeanInfo(componentModel.getClass());
// } catch (IntrospectionException ex) {
// throw new WebApplicationException(ex);
// }
//
// Arrays
// .stream(beanInfo.getPropertyDescriptors())
// .forEach(
// propertyDesc -> setComponentPropertyFromJson(componentModel,
// propertyDesc,
// data));
} }
/** /**
@ -561,7 +574,7 @@ public class Components {
} }
} catch (IllegalAccessException } catch (IllegalAccessException
| InvocationTargetException ex) { | InvocationTargetException ex) {
throw new WebApplicationException(ex); throw new WebApplicationException(ex);
} }
} }