CpDataLevelMapDeserializer implements T212Deserializer<Map<String,Object>>, Configured<CpDataLevelMapDeserializer> { @Deprecated private void verify(Map<String, Object> result) throws T212FormatException { if(!ALLOW_MISSING_FIELD.enabledIn(verifyFeature)){ Stream<DataElement> stream = Stream.of(DataElement.values()) .filter(DataElement::isRequired); if(result.containsKey(DataElement.Flag.name())){ String f = (String) result.get(DataElement.Flag.name()); int flag = Integer.valueOf(f); if(DataFlag.D.isMarked(flag)){ stream = Stream.concat(stream,Stream.of(DataElement.PNO, DataElement.PNUM)); } } Optional<DataElement> missing = stream .filter(e -> !result.containsKey(e.name())) .findFirst(); if(missing.isPresent()){ T212FormatException.field_is_missing(PacketElement.DATA,missing.get().name()); } } if(result.containsKey(DataElement.CP.name())){ Map<String,Object> cp = (Map) result.get(DataElement.CP.name()); if(!ALLOW_MISSING_FIELD.enabledIn(verifyFeature)){ Stream<DataElement> stream = Stream.of(DataElement.values()) .filter(DataElement::isRequired); if(result.containsKey(DataElement.Flag.name())){ String f = (String) result.get(DataElement.Flag.name()); int flag = Integer.valueOf(f); if(DataFlag.D.isMarked(flag)){ stream = Stream.concat(stream,Stream.of(DataElement.PNO, DataElement.PNUM)); } } Optional<DataElement> missing = stream .filter(e -> !result.containsKey(e.name())) .findFirst(); if(missing.isPresent()){ T212FormatException.field_is_missing(PacketElement.DATA,missing.get().name()); } } } }  @Override void configured(Configurator<CpDataLevelMapDeserializer> configurator); @SuppressWarnings("Duplicates") @Override Map<String, Object> deserialize(T212Parser parser); Map<String, Object> deserialize(char[] data); void setVerifyFeature(int verifyFeature); void setSegmentParserConfigurator(Configurator<SegmentParser> segmentParserConfigurator); void setSegmentDeserializer(SegmentDeserializer<Map<String, Object>> segmentDeserializer); void setValidator(Validator validator);  }
@Test public void testVerify(){ String data = "##0139ST=32;CN=2011;PW=123456;MN=LD130133000015;CP=&&DataTime=20160824003817000;B01-Rtd=36.91;011-Rtd=231.0,011-Flag=N;060-Rtd=1.803,060-Flag=N&&4980\r\n"; StringReader reader = new StringReader(data); T212Parser t212Parser = new T212Parser(reader); T212Configurator configurator = new T212Configurator(); int vFeature = Feature.collectFeatureDefaults(VerifyFeature.class); vFeature = vFeature | ALLOW_MISSING_FIELD.getMask(); vFeature = vFeature | ALLOW_VALUE_NOT_IN_RANGE.getMask(); configurator.setVerifyFeature(vFeature); configurator.setValidator(Validation.buildDefaultValidatorFactory().getValidator()); configurator.setParserFeature(Feature.collectFeatureDefaults(ParserFeature.class)); CpDataLevelMapDeserializer deserializer = new CpDataLevelMapDeserializer(); deserializer.configured(configurator); try (T212Parser parser = t212Parser) { deserializer.deserialize(parser); } catch (T212FormatException e) { e.printStackTrace(); assert true; return; } catch (IOException e) { e.printStackTrace(); } assert false; }