Created
December 18, 2018 07:52
-
-
Save sunzcdev/53624edb8f9cd09db2fde0ed64dc79fc to your computer and use it in GitHub Desktop.
十六进制字符串转javaBean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static <T> T hex2Bean(String str, Class<T> deviceAuthClass) { | |
try { | |
str = str.replace(" ", ""); | |
byte[] array = new BigInteger(str, 16).toByteArray(); | |
IoBuffer buffer = IoBuffer.wrap(array); | |
Constructor<T> cons = deviceAuthClass.getConstructor(IoBuffer.class); | |
return cons.newInstance(buffer); | |
} catch (NoSuchMethodException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} catch (InstantiationException e) { | |
e.printStackTrace(); | |
} catch (InvocationTargetException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment