Backport #1662 fix for 2.9(.8)
diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x
index 1acb48b..546a684 100644
--- a/release-notes/VERSION-2.x
+++ b/release-notes/VERSION-2.x
@@ -4,6 +4,11 @@
 === Releases === 
 ------------------------------------------------------------------------
 
+2.9.8 (not yet released)
+
+#1662: `ByteBuffer` serialization is broken if offset is not 0
+ (reported by j-baker@github)
+
 2.9.7 (19-Sep-2018)
 
 #2060: `UnwrappingBeanPropertyWriter` incorrectly assumes the found serializer is
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ByteBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ByteBufferSerializer.java
index d381b2b..302b4ed 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ByteBufferSerializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ByteBufferSerializer.java
@@ -20,7 +20,7 @@
     {
         // first, simple case when wrapping an array...
         if (bbuf.hasArray()) {
-            gen.writeBinary(bbuf.array(), 0, bbuf.limit());
+            gen.writeBinary(bbuf.array(), bbuf.arrayOffset(), bbuf.limit());
             return;
         }
         // the other case is more complicated however. Best to handle with InputStream wrapper.
diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/JDKTypeSerializationTest.java b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/JDKTypeSerializationTest.java
index 055fdf8..643e901 100644
--- a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/JDKTypeSerializationTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/JDKTypeSerializationTest.java
@@ -122,13 +122,12 @@
         assertEquals(quote("void"), MAPPER.writeValueAsString(Void.TYPE));
     }
 
-    // [JACKSON-789]
     public void testCharset() throws IOException
     {
         assertEquals(quote("UTF-8"), MAPPER.writeValueAsString(Charset.forName("UTF-8")));
     }
 
-    // [Issue#239]: Support serialization of ByteBuffer
+    // [databind#239]: Support serialization of ByteBuffer
     public void testByteBuffer() throws IOException
     {
         final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
@@ -142,6 +141,19 @@
         assertEquals(exp, MAPPER.writeValueAsString(bbuf2));
     }
 
+    // [databind#1662]: Sliced ByteBuffers
+    public void testSlicedByteBuffer() throws IOException
+    {
+        final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
+        String exp = MAPPER.writeValueAsString(new byte[] { 3, 4, 5 });
+        ByteBuffer bbuf = ByteBuffer.wrap(INPUT_BYTES);
+
+        bbuf.position(2);
+        ByteBuffer slicedBuf = bbuf.slice();
+
+        assertEquals(exp, MAPPER.writeValueAsString(slicedBuf));
+    }
+
     // Verify that efficient UUID codec won't mess things up:
     public void testUUIDs() throws IOException
     {