In the simple example, we did not need any additional information to convert Wiki Markup to ADF. However, this is often not enough information for a correct conversion because Wiki Markup and ADF represent some items very differently. Since Wiki Markup is meant to be written by humans, it usually has human-readable references to people, media attachments, and Jira issue keys. Successful conversion of these items requires a mapping of these to the identifiers and Jira site links that ADF requires.
1 2 3 4 5 6 7 8 9Hello, [~crf]! I took a couple of screenshots of the problem... Could you take a look at them? * !screenshot1.png|thumbnail! * !screenshot2.png|thumbnail! Also, I think JRASERVER-9 might be a duplicate...
Since this Wiki Markup includes attachments, a mention, and an issue key, we need to provide additional information through the conversion context. First, let's see what happens if no conversion context is provided:
1 2 3 4 5AdfJackson2 adfJackson2 = new AdfJackson2(); WikiMarkupTransformer transformer = WikiMarkupTransformer.using(adfJackson2.jsonParser()); Doc adf = transformer.parse(wiki); System.out.println(adfJackson2.pretty().marshall(adf));
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71{ "type" : "doc", "version" : 1, "content" : [ { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "Hello, " }, { "type" : "mention", "attrs" : { "id" : "crf" } }, { "type" : "text", "text" : "!" } ] }, { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "I took a couple of screenshots of the problem... Could you take a look at them?" } ] }, { "type" : "bulletList", "content" : [ { "type" : "listItem", "content" : [ { "type" : "mediaSingle", "content" : [ { "type" : "media", "attrs" : { "type" : "file", "id" : "screenshot1.png", "collection" : "", "width" : 200, "height" : 183 } } ], "attrs" : { "layout" : "center" } } ] }, { "type" : "listItem", "content" : [ { "type" : "mediaSingle", "content" : [ { "type" : "media", "attrs" : { "type" : "file", "id" : "screenshot2.png", "collection" : "", "width" : 200, "height" : 183 } } ], "attrs" : { "layout" : "center" } } ] } ] }, { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "Also, I think JRASERVER-9 might be a duplicate..." } ] } ] }
There are several problems with the resulting ADF:
crf as its id. This is not what an Atlassian Account ID normally looks like. It should probably be something more like 123456:8d913e2b-5621-4180-b6f9-b45a156f6e5a. This means that the mention node will not work. This happened because the conversion context did not have a mapping for mentions of the user crf, so it just left it alone.Provided we know about this problem in advance, we can avoid it by providing these values to the conversion context before we request the conversion. That would look like this:
1 2 3 4 5 6 7 8 9 10AdfJackson2 adfJackson2 = new AdfJackson2(); WikiMarkupTransformer transformer = WikiMarkupTransformer.using(adfJackson2.jsonParser()); transformer.context().conversion() .mention("crf", "123456:8d913e2b-5621-4180-b6f9-b45a156f6e5a") .media("screenshot1.png", "f2e12587-44fc-4407-9544-78dbf565a0d3") .media("screenshot2.png", "e581b41b-c21f-47f3-b48f-2f509d0143d1") .inlineCard("JRASERVER-9", "https://jira.atlassian.com/browse/JRASERVER-9"); Doc adf = transformer.parse(wiki); System.out.println(adfJackson2.pretty().marshall(adf));
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79{ "type" : "doc", "version" : 1, "content" : [ { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "Hello, " }, { "type" : "mention", "attrs" : { "id" : "123456:8d913e2b-5621-4180-b6f9-b45a156f6e5a" } }, { "type" : "text", "text" : "!" } ] }, { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "I took a couple of screenshots of the problem... Could you take a look at them?" } ] }, { "type" : "bulletList", "content" : [ { "type" : "listItem", "content" : [ { "type" : "mediaSingle", "content" : [ { "type" : "media", "attrs" : { "type" : "file", "id" : "f2e12587-44fc-4407-9544-78dbf565a0d3", "collection" : "", "width" : 200, "height" : 183 } } ], "attrs" : { "layout" : "center" } } ] }, { "type" : "listItem", "content" : [ { "type" : "mediaSingle", "content" : [ { "type" : "media", "attrs" : { "type" : "file", "id" : "e581b41b-c21f-47f3-b48f-2f509d0143d1", "collection" : "", "width" : 200, "height" : 183 } } ], "attrs" : { "layout" : "center" } } ] } ] }, { "type" : "paragraph", "content" : [ { "type" : "text", "text" : "Also, I think " }, { "type" : "inlineCard", "attrs" : { "url" : "https://jira.atlassian.com/browse/JRASERVER-9#icft=JRASERVER-9" } }, { "type" : "text", "text" : " might be a duplicate..." } ] } ] }
Now the mention and media nodes get their respective mapped IDs and the issue key is correctly replaced with an inlineCard.
The process is similar for conversions in the reverse direction. Note that in this direction the inline card information does not need to be specified and that there are some differences from the original Wiki Markup. These differences are expected.
1 2 3 4 5 6 7transformer.context().conversion() .mention("123456:8d913e2b-5621-4180-b6f9-b45a156f6e5a", "crf") .media("f2e12587-44fc-4407-9544-78dbf565a0d3", "screenshot1.png") .media("e581b41b-c21f-47f3-b48f-2f509d0143d1", "screenshot2.png"); String roundTrip = transformer.encode(adf); System.out.println(roundTrip);
1 2 3 4 5 6 7 8 9Hello, [~crf]! I took a couple of screenshots of the problem... Could you take a look at them? * !screenshot1.png|width=200,height=183! * !screenshot2.png|width=200,height=183! Also, I think [JRASERVER-9] might be a duplicate...
Rate this page: