From aab52994575ea7688ed33921e7f72b1cb64a49b2 Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 8 Aug 2018 17:18:28 +0000 Subject: [PATCH] CcmNG: Fix git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5664 8810af33-2d31-482b-a856-94f89814c4df --- .../org/libreccm/pagemodel/rs/Components.java | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/ccm-core/src/main/java/org/libreccm/pagemodel/rs/Components.java b/ccm-core/src/main/java/org/libreccm/pagemodel/rs/Components.java index 38fd3fd42..d5d69c784 100644 --- a/ccm-core/src/main/java/org/libreccm/pagemodel/rs/Components.java +++ b/ccm-core/src/main/java/org/libreccm/pagemodel/rs/Components.java @@ -296,14 +296,15 @@ public class Components { final ComponentModel componentModel) { final Class clazz = Objects - .requireNonNull(componentModel.getClass()); + .requireNonNull(componentModel) + .getClass(); final ComponentModelJsonConverter jsonConverter - = findJsonConverter(clazz) - .orElseThrow(() -> new WebApplicationException(String.format( + = findJsonConverter(clazz) + .orElseThrow(() -> new WebApplicationException(String.format( "No JSON converter available for component model \"%s\".", clazz.getName()))); - + return jsonConverter.toJson(componentModel); // Objects.requireNonNull(componentModel); @@ -394,9 +395,9 @@ public class Components { try { componentModel = clazz.getConstructor().newInstance(); } catch (IllegalAccessException - | InstantiationException - | InvocationTargetException - | NoSuchMethodException ex) { + | InstantiationException + | InvocationTargetException + | NoSuchMethodException ex) { throw new WebApplicationException(ex); } @@ -453,19 +454,31 @@ public class Components { final JsonObject data, final ComponentModel componentModel) { - final BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(componentModel.getClass()); - } catch (IntrospectionException ex) { - throw new WebApplicationException(ex); - } + final Class clazz = Objects + .requireNonNull(componentModel) + .getClass(); - Arrays - .stream(beanInfo.getPropertyDescriptors()) - .forEach( - propertyDesc -> setComponentPropertyFromJson(componentModel, - propertyDesc, - data)); + final ComponentModelJsonConverter jsonConverter + = findJsonConverter(clazz) + .orElseThrow(() -> new WebApplicationException(String.format( + "No JSON converter available for component model \"%s\".", + clazz.getName()))); + + 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 - | InvocationTargetException ex) { + | InvocationTargetException ex) { throw new WebApplicationException(ex); } }