Repository: goccy/go-yaml (go)

Issue:
Cannot detect it is multiline string or object
Related to: #75 (fixed by #78)

if the receiver type is `interface{}` and unmarshaling with `UnmarshalYAML([]byte)`, it seems impossible to detect it is multiline string or object.

e.g. the `value` in https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/api-with-examples.yaml#L18 and the `value` in https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/api-with-examples.yaml#L51 have same type but the result of unmarshal is not same, they are defined as `interface{}` and former one should be unmarshaled to `map[string]interface{}`, later one should unmarshaled to `string`

before #78, the passed bytes contains `|` at first character so we could detect it is string or object

is there any way to detect? (or, should revert the change?)

Pull request description:
Fix decoding for literal with BytesUnmarshaler
resolve #89

Add `|` header to string for decoding literal

Patch:
diff --git a/ast/ast.go b/ast/ast.go
index 1a88f2e..df51140 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -472,7 +472,7 @@ func (n *LiteralNode) AddColumn(col int) {
 
 // GetValue returns string value
 func (n *LiteralNode) GetValue() interface{} {
-	return n.Value.GetValue()
+	return n.String()
 }
 
 // String literal to text


Test patch:
diff --git a/decode_test.go b/decode_test.go
index 1dfeb6b..254ab30 100644
--- a/decode_test.go
+++ b/decode_test.go
@@ -1585,3 +1585,35 @@ func TestUnmarshalablePtrInt(t *testing.T) {
 		}
 	})
 }
+
+type literalContainer struct {
+	v string
+}
+
+func (c *literalContainer) UnmarshalYAML(v []byte) error {
+	var lit string
+	if err := yaml.Unmarshal(v, &lit); err != nil {
+		return err
+	}
+	c.v = lit
+	return nil
+}
+
+func TestDecode_Literal(t *testing.T) {
+	yml := `---
+value: |
+  {
+     "key": "value"
+  }
+`
+	var v map[string]*literalContainer
+	if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
+		t.Fatalf("failed to unmarshal %+v", err)
+	}
+	if v["value"] == nil {
+		t.Fatal("failed to unmarshal literal with bytes unmarshaler")
+	}
+	if v["value"].v == "" {
+		t.Fatal("failed to unmarshal literal with bytes unmarshaler")
+	}
+}